Skip to content

Nested JS Class in JS Class with Scala companion crashes compiler #4511

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 Jun 12, 2021 · 3 comments · Fixed by #4512
Closed

Nested JS Class in JS Class with Scala companion crashes compiler #4511

gzm0 opened this issue Jun 12, 2021 · 3 comments · Fixed by #4512
Assignees
Labels
bug Confirmed bug. Needs to be fixed.
Milestone

Comments

@gzm0
Copy link
Contributor

gzm0 commented Jun 12, 2021

Minimum reproducible example (discovered while working on #4502):

class A extends js.Object {
  class B extends js.Object
  object B
}

Makes this assertion fail:

assert(static,
s"Found more than one instance getter to export for name $jsName.")

Crash report:

[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]   Found more than one instance getter to export for name Literal(B).
[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/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.12.14.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.6.1-SNAPSHOT.jar -Xplugin:/home/tos/gh/scala-js/compiler/.2.12/target/scala-2.12/scalajs-compiler_2.12.14-1.6.1-SNAPSHOT.jar
[error] 
[error]   last tree to typer: This(object A$B)
[error]        tree position: line 13 of /home/tos/gh/scala-js/examples/helloworld/src/main/scala/helloworld/HelloWorld.scala
[error]             tree tpe: helloworld.A#A$B.type
[error]               symbol: object A$B in package helloworld
[error]    symbol definition: class A$B extends Object (a ModuleClassSymbol)
[error]       symbol package: helloworld
[error]        symbol owners: object A$B
[error]            call site: object A$B in package helloworld in package helloworld
[error] 
[error] == Source file context for tree position ==
[error] 
[error]     10 
[error]     11 class A extends js.Object {
[error]     12   class B extends js.Object
[error]     13   object B
[error]     14 }
[error]     15 
[error] one error found
[error] (helloworld2_12 / Compile / compileIncremental) Compilation failed
[error] Total time: 1 s, completed Jun 12, 2021, 5:48:29 PM
@gzm0 gzm0 added the bug Confirmed bug. Needs to be fixed. label Jun 12, 2021
@gzm0 gzm0 self-assigned this Jun 12, 2021
@gzm0
Copy link
Contributor Author

gzm0 commented Jun 12, 2021

Note that renaming either of them works:

class A extends js.Object {
  @JSName("C")
  class B extends js.Object

  object B
}

@gzm0
Copy link
Contributor Author

gzm0 commented Jun 12, 2021

Really, the fix here is to simply report an error.

@gzm0
Copy link
Contributor Author

gzm0 commented Jun 12, 2021

The same happens with this:

class C extends js.Object {
  def a = "asdf"

  @JSName("a")
  def b = "asdf"
}

gzm0 added a commit to gzm0/scala-js that referenced this issue Jun 12, 2021
@gzm0 gzm0 linked a pull request Jun 12, 2021 that will close this issue
@sjrd sjrd added this to the v1.6.1 milestone Jun 12, 2021
gzm0 added a commit to gzm0/scala-js that referenced this issue Jun 13, 2021
sjrd added a commit that referenced this issue Jun 13, 2021
Fix #4511: Report an error on duplicate non-static getters
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