question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compiler crash in 2.11 when inheriting from a trait with a JS module

See original GitHub issue
trait Foo {
  object jsObj extends js.Object
}

class Bar extends Foo

Expected: Compiles

Actual:

[info] compiling 1 Scala source to /home/tos/gh/scala-js/examples/helloworld/.2.11/target/scala-2.11/classes ...
[error] Error while emitting HelloWorld.scala
[error] assertion failed: 
[error]   object Foo$jsObj at source-/home/tos/gh/scala-js/examples/helloworld/src/main/scala/helloworld/HelloWorld.scala,line-15,offset=200: jsClassValue.isDefined = false but isInnerNonNativeJSClass = true
[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.11.12
[error]     compiler version: version 2.11.12
[error]   reconstructed args: -encoding utf8 -deprecation -feature -Xplugin:/home/tos/gh/scala-js/compiler/.2.11/target/scala-2.11/scalajs-compiler_2.11.12-1.12.1-SNAPSHOT.jar -classpath /home/tos/gh/scala-js/examples/helloworld/.2.11/target/scala-2.11/classes:/home/tos/gh/scala-js/library/.2.11/target/scala-2.11/scalajs-library_2.11-1.12.1-SNAPSHOT.jar:/home/tos/gh/scala-js/javalib-public/target/classes:/home/tos/gh/scala-js/javalib-public/target/scalajs-javalib-1.12.1-SNAPSHOT.jar -bootclasspath /home/tos/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.11.12/scala-library-2.11.12.jar -Xfatal-warnings -unchecked
[error] 
[error]   last tree to typer: term jsObj$module
[error]        tree position: line 12 of /home/tos/gh/scala-js/examples/helloworld/src/main/scala/helloworld/HelloWorld.scala
[error]             tree tpe: <notype>
[error]               symbol: variable jsObj$module in object Foo$class
[error]    symbol definition: var jsObj$module: helloworld.Foo$jsObj.type (a TermSymbol)
[error]       symbol package: helloworld
[error]        symbol owners: variable jsObj$module -> object Foo$class
[error]            call site: object Foo$jsObj in package helloworld in package helloworld
[error] 
[error] == Source file context for tree position ==
[error] 
[error]      9 
[error]     10 trait Foo {
[error]     11   object jsObj extends js.Object
[error]     12 }
[error]     13 
[error]     14 class Bar extends Foo
[error] one error found
[error] (helloworld2_11 / Compile / compileIncremental) Compilation failed
[error] Total time: 1 s, completed Dec 4, 2022, 12:05:44 PM

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
gzm0commented, Dec 4, 2022

Makes me want to drop 2.11 😕

1reaction
sjrdcommented, Dec 4, 2022

Er, that seems pretty bad. 😦

Trait mixin was indeed completely redone in 2.12. I guess in 2.11, for module accessors, mixin discards the previous getter/constructor and recreates a new one in the subclass. So the transformation done by xplicitlocaljs gets erased.

In theory we could re-intercept the $lzycompute method for module accessor mixins in the back-end, and regenerate them entirely.

But perhaps, as you say, it might be the straw that breaks the 2.11 camel’s back. In that case we should create an RFC issue to drop Scala 2.11 and publicize it to get feedback. Would you like to create the issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tobias Schlatter gzm0 - GitHub
Investigate why tools-sbtplugin tasks fail on Java 16 Dec 10 ; Drop Scala 2.12.1 Dec 8 ; Compiler crash in 2.11 when inheriting...
Read more >
[Solved]-How can I work around a Scala compiler crash?-scala
What you want to do is to try narrowing down what's causing the problem. The easiest way to do this in most projects...
Read more >
Inheriting self-typed trait with another trait in Scala
The 'concrete' module is meant to be implemented by 3rd parties, so exposing the registry to them seems kinda ugly.
Read more >
Ammonite
Compiler -crash Robustness​​ The default Scala REPL throws away all your work if the compiler crashes. This doesn't make any sense, because all...
Read more >
sbt Reference Manual — Combined Pages
From sbt shell, press up-arrow twice to find the compile command that you executed at the beginning. sbt:foo-build> compile. Getting help. Use the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found