Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prefix method call expansion is ruining the dependent method types party #4518

Open
scabug opened this issue Apr 27, 2011 · 12 comments
Open

Comments

@scabug
Copy link

scabug commented Apr 27, 2011

=== What steps will reproduce the problem (please be specific and use wikiformatting)? ===
scalac -Xexperimental Broke.scala

class Broke {

  val tempval = new AnyRef {val roleA = new AnyRef with Bar}.roleA

  new AnyRef {} -: tempval // when not assigning to anything, no problem
  val broke_val = new AnyRef {} -: tempval // type mismatch error only when assigning

  trait Foo[AnyRef] {  }

  trait Bar extends Foo[AnyRef] {
    def -:(core: AnyRef): this.type with Foo[core.type] = throw new Exception()
  }
} 

=== What is the expected behavior? ===
Compiles without error, as it did with 2.7.7 and 2.8.1

=== What do you see instead? ===
Broke.scala:6: error: type mismatch;
found : Broke.this.tempval.type with Broke.this.Foo[x$$2.type(in value broke_val)] where type x$$2.type(in value broke_val) <: java.lang.Object with Singleton
required: Broke.this.tempval.type with Broke.this.Foo[x$$2.type(in value broke_val)] forSome { type x$$2.type(in value broke_val) <: java.lang.Object with Singleton }
val broke_val = new AnyRef {} -: tempval // type mismatch error only when assigning
^
one error found

=== Additional information ===
(for instance, a link to a relevant mailing list discussion)

=== What versions of the following are you using? ===

  • Scala: 2.9RC1
  • Java: n/a
  • Operating system: Debian Linux sid
@scabug
Copy link
Author

scabug commented Apr 27, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4518?orig=1
Reporter: tupshin
See #1980
Duplicates #1980

@scabug
Copy link
Author

scabug commented Apr 29, 2011

@odersky said:
It seems to have to do with the fact that the Singleton upper bounds is stripped somewhere.

@scabug
Copy link
Author

scabug commented Apr 29, 2011

@dragos said:
Actually, this fails the same way with 2.8.1, but works with 2.8.0.

@scabug
Copy link
Author

scabug commented May 23, 2011

@adriaanm said (edited on May 23, 2011 8:47:14 AM UTC):
changing the broken_val line to

val broke_val = tempval.-:(new AnyRef {}) // type mismatch error only when assigning

works around the bug... the prefix method call expansion seems to be ruining the dependent method types party

smaller test case and typer output:

object Test {
  trait Foo[T] 

  trait Bar {
    def -:(core: AnyRef): Foo[core.type] = error("")
  }

  val tempval: Bar = error("")
  val cor: AnyRef = error("")
  
  val ok : Foo[cor.type] = tempval.-:(cor)
  val oops : Foo[cor.type] = cor -: tempval 
}
    private[this] val ok: Test.Foo[Test.cor.type] = Test.this.tempval.-:(Test.this.cor);
    <stable> <accessor> def ok: Test.Foo[Test.cor.type] = Test.this.ok;
    private[this] val oops: Test.Foo[Test.cor.type] = {
      <synthetic> val x$1: AnyRef = Test.this.cor;
      Test.this.tempval.-:(x$1)
    };
    <stable> <accessor> def oops: Test.Foo[Test.cor.type] = Test.this.oops

@scabug
Copy link
Author

scabug commented Dec 5, 2012

@retronym said:
Merging into #1980

@som-snytt
Copy link

It wasn't fixed under the linked ticket after all.

@magnolia-k
Copy link

The code in this example can be compiled.

Also, the -Xexperimental option has been deprecated since Scala 2.13.0, so the issue itself can be closed.

@SethTisue SethTisue removed this from the Backlog milestone Jul 11, 2021
@som-snytt
Copy link

som-snytt commented Jul 11, 2021

It is added as a pos test in the linked PR, which may make it into 2.13.7. Presumably it did not compile on pre-release 2.13.

Edit: I couldn't reproduce whatever failure I witnessed. Feb 2019 was a couple of computers ago. I tried M5 and RC1.

@som-snytt
Copy link

It's the Adriaan reduction that fails. That is because rassoc rewrite extracts the expression in parser, so some context is lost; the linked PR rewrites in typer.

@som-snytt som-snytt reopened this Jan 25, 2023
@SethTisue SethTisue added this to the Backlog milestone Aug 8, 2023
@SethTisue
Copy link
Member

SethTisue commented Nov 7, 2023

@som-snytt (care to revise the issue title, if we're leaving this open? the current title attracted my attention since -Xexperimental no longer exists)

@som-snytt
Copy link

som-snytt commented Nov 7, 2023

I'm glad I left a few breadcrumbs for future self. Here's Adriaan's reduction again:

object Test {
  trait Foo[T]

  trait Bar {
    def -:(core: AnyRef): Foo[core.type] = error("")
  }

  val tempval: Bar = error("")
  val cor: AnyRef = error("")

  val ok : Foo[cor.type] = tempval.-:(cor)
  val oops : Foo[cor.type] = cor -: tempval

  def error(s: String) = ???
}

currently 2.13.12

t4518b.scala:13: error: type mismatch;
 found   : Test.Foo[rassoc$1.type]
 required: Test.Foo[Test.cor.type]
  val oops : Foo[cor.type] = cor -: tempval
                                 ^
1 error

I see that is a pos test on my branch but not yet pushed to the PR. I will need to catch up because

On branch issue/5073-rassoc-method-value
Your branch and 'upstream/2.13.x' have diverged,
and have 1 and 1014 different commits each, respectively.

oh man, that's sbt 1.8.2, I have to downgrade my jdk.

OK, it compiles on that branch. I suspect Lukas was just giving me a hard time on the last mile. It will take me a bit to rebase because I'm starting season 2 of Dawson's Creek, they're literally still kissing. I think cliffhanger is specialized lingo for whatever generation that is.

@som-snytt som-snytt changed the title -Xexperimental dependent types regression prefix method call expansion seems to be ruining the dependent method types party Nov 7, 2023
@som-snytt som-snytt changed the title prefix method call expansion seems to be ruining the dependent method types party prefix method call expansion is ruining the dependent method types party Nov 7, 2023
@som-snytt
Copy link

I can't improve on Adriaan's description, except one tweak for length.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants