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.

`abstract case class` breaks Scala.js sourcemaps?

See original GitHub issue

(originally reported by @mn98 as a possible Cats Effect bug)

Compiler version

3.1.1-RC2

Minimized code

// build.sbt
scalaVersion := "3.1.1-RC2"
scalaJSUseMainModuleInitializer := true
enablePlugins(ScalaJSPlugin, ScalaJSBundlerPlugin)

// project/plugins.sbt
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.8.0")
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.20.0")

// src/main/scala/Main.scala
object Main {
  def main(args: Array[String]): Unit = ExitCode(0)
}
abstract case class ExitCode private (code: Int)
object ExitCode {
  def apply(i: Int): ExitCode = new ExitCode(i & 0xff) {}
  val Success: ExitCode = ExitCode(0)
}

Output

sbt> Compile / fastOptJS / webpack
[info] compiling 1 Scala source to /workspace/http4s4tw/target/scala-3.1.1-RC2/classes ...
[info] Updating NPM dependencies
[info] Fast optimizing /workspace/http4s4tw/target/scala-3.1.1-RC2/http4s4tw-fastopt
[error] npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
[error] npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
[error] npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
[error] npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
[error] npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
[error] npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
[info] added 603 packages, and audited 604 packages in 10s
[info] 20 packages are looking for funding
[info]   run `npm fund` for details
[info] 14 vulnerabilities (8 moderate, 6 high)
[info] To address issues that do not require attention, run:
[info]   npm audit fix
[info] To address all issues, run:
[info]   npm audit fix --force
[info] Run `npm audit` for details.
[info] Writing scalajs.webpack.config.js
[info] Bundling the application with its NPM dependencies
[error] /workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/source-map/lib/source-map-generator.js:298
[error]       throw new Error('Invalid mapping: ' + JSON.stringify({
[error]       ^
[error] Error: Invalid mapping: {"generated":{"line":969,"column":24},"source":"/workspace/http4s4tw/src/main/scala/Main.scala","original":{"line":4,"column":-1},"name":"toString"}
[error]     at SourceMapGenerator_validateMapping [as _validateMapping] (/workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/source-map/lib/source-map-generator.js:298:13)
[error]     at SourceMapGenerator_addMapping [as addMapping] (/workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/source-map/lib/source-map-generator.js:110:12)
[error]     at /workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/source-map/lib/source-node.js:351:13
[error]     at SourceNode_walk [as walk] (/workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/source-map/lib/source-node.js:230:9)
[error]     at SourceNode_walk [as walk] (/workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/source-map/lib/source-node.js:226:13)
[error]     at SourceNode_walk [as walk] (/workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/source-map/lib/source-node.js:226:13)
[error]     at SourceNode_toStringWithSourceMap [as toStringWithSourceMap] (/workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/source-map/lib/source-node.js:342:8)
[error]     at ConcatSource.proto.sourceAndMap (/workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/webpack-sources/lib/SourceAndMapMixin.js:29:32)
[error]     at CachedSource.sourceAndMap (/workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/webpack-sources/lib/CachedSource.js:58:31)
[error]     at getTaskForFile (/workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/webpack/lib/SourceMapDevToolPlugin.js:37:30)
[error]     at /workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/webpack/lib/SourceMapDevToolPlugin.js:136:20
[error]     at Array.forEach (<anonymous>)
[error]     at /workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/webpack/lib/SourceMapDevToolPlugin.js:130:12
[error]     at SyncHook.eval [as call] (eval at create (/workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:7:1)
[error]     at SyncHook.lazyCompileHook (/workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/tapable/lib/Hook.js:154:20)
[error]     at /workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/webpack/lib/Compilation.js:1319:42
[error]     at AsyncSeriesHook.eval [as callAsync] (eval at create (/workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
[error]     at AsyncSeriesHook.lazyCompileHook (/workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/tapable/lib/Hook.js:154:20)
[error]     at /workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/webpack/lib/Compilation.js:1315:36
[error]     at AsyncSeriesHook.eval [as callAsync] (eval at create (/workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
[error]     at AsyncSeriesHook.lazyCompileHook (/workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/tapable/lib/Hook.js:154:20)
[error]     at /workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/webpack/lib/Compilation.js:1311:32
[error]     at AsyncSeriesHook.eval [as callAsync] (eval at create (/workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
[error]     at AsyncSeriesHook.lazyCompileHook (/workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/tapable/lib/Hook.js:154:20)
[error]     at Compilation.seal (/workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/webpack/lib/Compilation.js:1248:27)
[error]     at /workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/webpack/lib/Compiler.js:625:18
[error]     at /workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/webpack/lib/Compilation.js:1171:4
[error]     at AsyncSeriesHook.eval [as callAsync] (eval at create (/workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
[error]     at AsyncSeriesHook.lazyCompileHook (/workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/tapable/lib/Hook.js:154:20)
[error]     at Compilation.finish (/workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/webpack/lib/Compilation.js:1163:28)
[error] Failure on parsing the output of webpack: No content to map due to end-of-input
[error]  at [Source: java.lang.ProcessImpl$ProcessPipeInputStream@3fa6bef7; line: 1, column: 0]
[error] You can try to manually execute the command
[error] node /workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/node_modules/webpack/bin/webpack --bail --profile --json --config /workspace/http4s4tw/target/scala-3.1.1-RC2/scalajs-bundler/main/scalajs.webpack.config.js
[error] 
[error] stack trace is suppressed; run last Compile / fastOptJS for the full output
[error] (Compile / fastOptJS / webpack) Non-zero exit code: 1
[error] Total time: 12 s, completed Jan 10, 2022, 4:01:39 PM

Expectation

Switching to Scala 2.13.7 there is no error.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
sjrdcommented, Jan 21, 2022

Is there any way for the Scala.js linker to detect it’s consuming IR generated by a pre-fix Scala 3 and apply an off-by-one correction?

No. It can detect if it’s consuming a previous version of the IR. But it cannot know whether that was emitted by Scala 2 or Scala 3, so it would still not know whether to apply the correction or not.

it (mildly) ~breaks the promise~ undoes the advantage of backwards-compatibility since everyone would have to republish.

Backwards compat is guaranteed when the old compiler did the right thing at the time it did it. In other words, we do not break correct IR. But if the compiler was buggy and emitted wrong code to begin with … there is little we can do.

This is not specific to Scala.js. If the JVM backend emits the wrong bytecode for some piece of program, the JVM is not going to fix it for you later. You have to recompile and republish with a fixed version of the compiler. This has happened in the past: I remember fixing myself the codegen for intValue << longValue in 2.12.something.

0reactions
armanbilgecommented, Jan 21, 2022

@sjrd Thanks for tracking this down! A question: assuming (IIUC) that this bug has affected all currently published Scala 3 SJSIR artifacts, it (mildly) breaks the promise undoes the advantage of backwards-compatibility since everyone would have to republish. Is there any way for the Scala.js linker to detect it’s consuming IR generated by a pre-fix Scala 3 and apply an off-by-one correction? Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hands-on Scala.js - Haoyi's Programming Blog
Scala.js is a compiler that compiles Scala source code to equivalent Javascript ... Here we are defining a Point case class which represents...
Read more >
Announcing Scala.js 0.6.11
Jul 27, 2016. We are pleased to announce the release of Scala.js 0.6.11! This release was mainly focused on optimizations.
Read more >
Scala case class vs object: how is it instantiated?
Your answer where you mentioned the constructor calling on an abstract val before it was initialized by the subclass gave me a clue....
Read more >
ScalaTags - GitHub Pages
ScalaTags is a small, fast XML/HTML/CSS construction library for Scala that takes fragments in plain Scala code that look like this: // import...
Read more >
Scala.js
Scala CLI can compile, run, test, and package Scala.js sources. ... import scala.scalajs.js case class Foo(txt: String) ... Emitted js source maps to:...
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