Skip to content

Compiler crashes on nested JS class with default constructor params with private companion #4526

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

Closed
gzm0 opened this issue Jul 10, 2021 · 1 comment · Fixed by #4527
Closed
Assignees
Labels
bug Confirmed bug. Needs to be fixed.
Milestone

Comments

@gzm0
Copy link
Contributor

gzm0 commented Jul 10, 2021

package helloworld

import scala.scalajs.js
import js.annotation._

class A {
  class B(x: Int = 1) extends js.Object

  private object B
}

object HelloWorld {
  def main(args: Array[String]): Unit = {
    val a = new A
    val x = new a.B()
    println(x)
  }
}

Crashes:

[info] compiling 1 Scala source to /home/tos/gh/scala-js/examples/helloworld/.2.12/target/scala-2.12/classes ...
[error] Error while emitting HelloWorld.scala
[error] assertion failed: 
[error]   need default getter for method helloworld.A$B.<init>
[error]      while compiling: /home/tos/gh/scala-js/examples/helloworld/src/main/scala/helloworld/HelloWorld.scala
[error]         during phase: jscode
[error]      library version: version 2.12.14
[error]     compiler version: version 2.12.14
[error]   reconstructed args: -bootclasspath /home/tos/.sbt/boot/scala-2.12.14/lib/scala-library.jar -deprecation -encoding utf8 -feature -unchecked -Xfatal-warnings -Wconf:cat=feature:w -Wconf:cat=unchecked:w -Wconf:cat=deprecation:w -Wconf:cat=deprecation:ws -Wconf:cat=feature:ws -Wconf:cat=optimizer:ws -classpath /home/tos/gh/scala-js/examples/helloworld/.2.12/target/scala-2.12/classes:/home/tos/gh/scala-js/library/.2.12/target/scala-2.12/scalajs-library_2.12-1.7.0-SNAPSHOT.jar -Xplugin:/home/tos/gh/scala-js/compiler/.2.12/target/scala-2.12/scalajs-compiler_2.12.14-1.7.0-SNAPSHOT.jar
[error] 
[error]   last tree to typer: TypeTree(class A$B)
[error]        tree position: line 20 of /home/tos/gh/scala-js/examples/helloworld/src/main/scala/helloworld/HelloWorld.scala
[error]             tree tpe: helloworld.A$B
[error]               symbol: class A$B in package helloworld
[error]    symbol definition: class A$B extends Object (a ClassSymbol)
[error]       symbol package: helloworld
[error]        symbol owners: class A$B
[error]            call site: object A$B in package helloworld in package helloworld
[error] 
[error] == Source file context for tree position ==
[error] 
[error]     17 object HelloWorld {
[error]     18   def main(args: Array[String]): Unit = {
[error]     19     val a = new A
[error]     20     val x = new a.B()
[error]     21     println(x)
[error]     22   }
[error]     23 }
[error] one error found
[error] (helloworld2_12 / Compile / compileIncremental) Compilation failed
[error] Total time: 1 s, completed Jul 10, 2021, 11:50:45 AM

This assertion triggers:

assert(defaultGetter.exists,
s"need default getter for method ${sym.fullName}")

@gzm0
Copy link
Contributor Author

gzm0 commented Jul 10, 2021

Discovered while working on #4502.

@gzm0 gzm0 added the bug Confirmed bug. Needs to be fixed. label Jul 10, 2021
@gzm0 gzm0 self-assigned this Jul 10, 2021
gzm0 added a commit to gzm0/scala-js that referenced this issue Jul 11, 2021
gzm0 added a commit to gzm0/scala-js that referenced this issue Jul 11, 2021
@gzm0 gzm0 linked a pull request Jul 11, 2021 that will close this issue
gzm0 added a commit to gzm0/scala-js that referenced this issue Jul 11, 2021
gzm0 added a commit to gzm0/scala-js that referenced this issue Jul 15, 2021
@sjrd sjrd added this to the v1.7.0 milestone Jul 16, 2021
gzm0 added a commit to gzm0/scala-js that referenced this issue Jul 18, 2021
sjrd added a commit that referenced this issue Jul 18, 2021
Fix #4526: Find module accessor of nested private companions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug. Needs to be fixed.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants