scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

Crash in Scala 2.13 when attempting to curry/eta expand a class constructor #12125

Open jackkoenig opened 4 years ago

jackkoenig commented 4 years ago

reproduction steps

using Scala 2.13.3,

I get inconsistent results between the console vs. normal compilation

Console

scala> class Foo(x: Int)(y: String)
class Foo

scala> new Foo(3) _
       ^
       error: Internal error: unable to find the outer accessor symbol of class

Standard compilation

class Foo(x: Int)(y: String)
object Foo {
  val mkFoo = new Foo(3) _
}
[error]
[error]   Unexpected New(TypeTree(class Foo)/example.Foo) reached GenBCode.
[error]   Call was genLoad(new example.Foo,Lexample/Foo;)
[error]      while compiling: /scratch/koenig/scala-crash/crash/src/main/scala/example/Hello.scala
[error]         during phase: jvm
[error]      library version: version 2.13.3
[error]     compiler version: version 2.13.3
[error]   reconstructed args: -bootclasspath /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/resources.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/jsse.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/jce.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/charsets.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/jfr.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/classes:/home/koenig/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.3/scala-library-2.13.3.jar -classpath /scratch/koenig/scala-crash/crash/target/scala-2.13/classes
[error]
[error]   last tree to typer: TypeTree(class String)
[error]        tree position: line 17 of /scratch/koenig/scala-crash/crash/src/main/scala/example/Hello.scala
[error]             tree tpe: String
[error]               symbol: final class String in package lang
[error]    symbol definition: final class String extends Serializable with Comparable with CharSequence (a ClassSymbol)
[error]       symbol package: java.lang
[error]        symbol owners: class String
[error]            call site: constructor Hello$delayedInit$body in class Hello$delayedInit$body in package example
[error]
[error] == Source file context for tree position ==
[error]
[error]     14 }
[error]     15
[error]     16 trait Greeting {
[error]     17   lazy val greeting: String = "hello"
[error]     18 }
[error]     19
[error] Error while emitting Hello.scala
[error]
[error]   Unexpected New(TypeTree(class Foo)/example.Foo) reached GenBCode.
[error]   Call was genLoad(new example.Foo,Lexample/Foo;)
[error]      while compiling: /scratch/koenig/scala-crash/crash/src/main/scala/example/Hello.scala
[error]         during phase: jvm
[error]      library version: version 2.13.3
[error]     compiler version: version 2.13.3
[error]   reconstructed args: -bootclasspath /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/resources.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/jsse.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/jce.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/charsets.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/jfr.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/classes:/home/koenig/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.3/scala-library-2.13.3.jar -classpath /scratch/koenig/scala-crash/crash/target/scala-2.13/classes
[error]
[error]   last tree to typer: TypeTree(class String)
[error]        tree position: line 17 of /scratch/koenig/scala-crash/crash/src/main/scala/example/Hello.scala
[error]             tree tpe: String
[error]               symbol: final class String in package lang
[error]    symbol definition: final class String extends Serializable with Comparable with CharSequence (a ClassSymbol)
[error]       symbol package: java.lang
[error]        symbol owners: class String
[error]            call site: constructor Hello$delayedInit$body in class Hello$delayedInit$body in package example
[error]
[error] == Source file context for tree position ==
[error]
[error]     14 }
[error]     15
[error]     16 trait Greeting {
[error]     17   lazy val greeting: String = "hello"
[error]     18 }
[error]     19
[error] two errors found

problem

Scala 2.12.12 gives the following

scala> class Foo(x: Int)(y: String)
defined class Foo

scala> new Foo(3) _
<console>:13: error: missing argument list for constructor Foo in class Foo
       new Foo(3) _
       ^

I'd expect the same error

NthPortal commented 4 years ago

incidentally, why can't you eta-expand a constructor?

jackkoenig commented 4 years ago

incidentally, why can't you eta-expand a constructor?

Great question, I only hit this because I assumed I could 🤷

SethTisue commented 4 years ago

related: #8729