Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Compiler crashes on overloaded methods with varargs of generic types on JS classes #18658

Closed
raquo opened this issue Oct 6, 2023 · 1 comment · Fixed by #18659
Closed

Compiler crashes on overloaded methods with varargs of generic types on JS classes #18658

raquo opened this issue Oct 6, 2023 · 1 comment · Fixed by #18659

Comments

@raquo
Copy link
Contributor

raquo commented Oct 6, 2023

Compiler version

Scala 3.3.1, Scala.js 1.14.0

Minimized code

object Foo {

  class Bar extends scala.scalajs.js.Object {

    def bar(v: String): Unit = ()

    def bar(v: Tuple2[Int, Int]*): Unit = ()
  }

  val x = new Bar

  x.bar("foo")
}

There's something about varargs with Tuple2 or Product2 that it does not like. Not every type causes this crash.

Output

Scala 3.3.1 compiler crashes (Scala 2.13.9 does not). Output below.

Note: I censored some paths with <projectpath> and <userhome>.

[info] compiling 4 Scala sources to <projectpath>/frontend/target/scala-3.3.1/classes ...

  unhandled exception while running genSJSIR on <projectpath>/frontend/src/main/scala/com/raquo/app/Utils.scala

  An unhandled exception was thrown in the compiler.
  Please file a crash report here:
  https://github.com/lampepfl/dotty/issues/new/choose

     while compiling: <no file>
        during phase: <no phase>
                mode: Mode(ImplicitsEnabled)
     library version: version 2.13.10
    compiler version: version 3.3.1
            settings: -bootclasspath <userhome>/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.3.1/scala3-library_3-3.3.1.jar:<userhome>/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.10/scala-library-2.13.10.jar -classpath <projectpath>/frontend/target/scala-3.3.1/classes:<projectpath>/shared/js/target/scala-3.3.1/classes:<userhome>/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_sjs1_3/3.3.1/scala3-library_sjs1_3-3.3.1.jar:<userhome>/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-js/scalajs-library_2.13/1.14.0/scalajs-library_2.13-1.14.0.jar:<userhome>/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/raquo/laminar_sjs1_3/16.0.0/laminar_sjs1_3-16.0.0.jar:<userhome>/.ivy2/local/org.scalablytyped/kurkle__color_sjs1_3/0.3.2-7ad9f8/jars/kurkle__color_sjs1_3.jar:<userhome>/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-js/scalajs-dom_sjs1_3/2.6.0/scalajs-dom_sjs1_3-2.6.0.jar:<userhome>/.ivy2/local/org.scalablytyped/std_sjs1_3/5.2-0c4c8a/jars/std_sjs1_3.jar:<userhome>/.ivy2/local/org.scalablytyped/chart_dot_js_sjs1_3/4.4.0-601239/jars/chart_dot_js_sjs1_3.jar:<userhome>/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/olvind/scalablytyped-runtime_sjs1_3/2.4.2/scalablytyped-runtime_sjs1_3-2.4.2.jar:<userhome>/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/github/plokhotnyuk/jsoniter-scala/jsoniter-scala-core_sjs1_3/2.23.5/jsoniter-scala-core_sjs1_3-2.23.5.jar:<userhome>/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-js/scalajs-javalib/1.14.0/scalajs-javalib-1.14.0.jar:<userhome>/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/raquo/airstream_sjs1_3/16.0.0/airstream_sjs1_3-16.0.0.jar:<userhome>/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/raquo/ew_sjs1_3/0.1.2/ew_sjs1_3-0.1.2.jar:<userhome>/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/io/github/cquiroz/scala-java-time_sjs1_3/2.5.0/scala-java-time_sjs1_3-2.5.0.jar:<userhome>/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/app/tulz/tuplez-full-light_sjs1_3/0.4.0/tuplez-full-light_sjs1_3-0.4.0.jar:<userhome>/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/portable-scala/portable-scala-reflect_sjs1_2.13/1.1.2/portable-scala-reflect_sjs1_2.13-1.1.2.jar:<userhome>/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/io/github/cquiroz/scala-java-locales_sjs1_3/1.5.1/scala-java-locales_sjs1_3-1.5.1.jar:<userhome>/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/io/github/cquiroz/cldr-api_sjs1_3/4.0.0/cldr-api_sjs1_3-4.0.0.jar -d <projectpath>/frontend/target/scala-3.3.1/classes -scalajs true

                tree: EmptyTree
       tree position: :<unknown>
           tree type: <notype>
              symbol: val <none>
           call site: package <root> in module class <root>

  == Source file context for tree position ==

[error] ## Exception when compiling 4 sources to <projectpath>/frontend/target/scala-3.3.1/classes
[error] scala.MatchError: AppliedType(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),class Tuple2),List(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),class Int), TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),class Int))) (of class dotty.tools.dotc.core.Types$CachedAppliedType)
[error] dotty.tools.backend.sjs.JSEncoding$.toTypeRefInternal(JSEncoding.scala:389)
[error] dotty.tools.backend.sjs.JSEncoding$.toIRType(JSEncoding.scala:311)
[error] dotty.tools.backend.sjs.JSExportsGen.typeTestForTpe(JSExportsGen.scala:929)
[error] dotty.tools.backend.sjs.JSExportsGen.$anonfun$32(JSExportsGen.scala:529)
[error] dotty.tools.backend.sjs.JSExportsGen.groupByWithoutHashCode$$anonfun$1(JSExportsGen.scala:957)
[error] scala.collection.immutable.List.foreach(List.scala:333)
[error] dotty.tools.backend.sjs.JSExportsGen.groupByWithoutHashCode(JSExportsGen.scala:963)
[error] dotty.tools.backend.sjs.JSExportsGen.genOverloadDispatchSameArgcRec(JSExportsGen.scala:529)
[error] dotty.tools.backend.sjs.JSExportsGen.genOverloadDispatchSameArgc(JSExportsGen.scala:494)
[error] dotty.tools.backend.sjs.JSExportsGen.$anonfun$31(JSExportsGen.scala:450)
[error] scala.collection.Iterator$$anon$9.next(Iterator.scala:584)
[error] scala.collection.immutable.List.prependedAll(List.scala:153)
[error] scala.collection.immutable.List$.from(List.scala:684)
[error] scala.collection.immutable.List$.from(List.scala:681)
[error] scala.collection.IterableOps$WithFilter.map(Iterable.scala:898)
[error] dotty.tools.backend.sjs.JSExportsGen.genExportMethodMultiAlts(JSExportsGen.scala:452)
[error] dotty.tools.backend.sjs.JSExportsGen.genOverloadDispatch(JSExportsGen.scala:419)
[error] dotty.tools.backend.sjs.JSExportsGen.genExportMethod(JSExportsGen.scala:389)
[error] dotty.tools.backend.sjs.JSExportsGen.genMemberExportOrDispatcher$$anonfun$1(JSExportsGen.scala:326)
[error] dotty.tools.backend.sjs.JSCodeGen.withNewLocalNameScope$$anonfun$1(JSCodeGen.scala:121)
[error] dotty.tools.backend.sjs.ScopedVar$.withScopedVars(ScopedVar.scala:33)
[error] dotty.tools.backend.sjs.JSCodeGen.withNewLocalNameScope(JSCodeGen.scala:122)
[error] dotty.tools.backend.sjs.JSExportsGen.genMemberExportOrDispatcher(JSExportsGen.scala:327)
[error] dotty.tools.backend.sjs.JSExportsGen.genJSClassDispatcher(JSExportsGen.scala:316)
[error] dotty.tools.backend.sjs.JSExportsGen.genJSClassDispatchers$$anonfun$1(JSExportsGen.scala:288)
[error] scala.collection.immutable.List.map(List.scala:246)
[error] dotty.tools.backend.sjs.JSExportsGen.genJSClassDispatchers(JSExportsGen.scala:288)
[error] dotty.tools.backend.sjs.JSCodeGen.genNonNativeJSClass(JSCodeGen.scala:593)
[error] dotty.tools.backend.sjs.JSCodeGen.genCompilationUnit$$anonfun$3$$anonfun$1(JSCodeGen.scala:239)
[error] dotty.tools.backend.sjs.ScopedVar$.withScopedVars(ScopedVar.scala:33)
[error] dotty.tools.backend.sjs.JSCodeGen.genCompilationUnit$$anonfun$3(JSCodeGen.scala:249)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.immutable.List.foreach(List.scala:333)
[error] dotty.tools.backend.sjs.JSCodeGen.genCompilationUnit(JSCodeGen.scala:251)
[error] dotty.tools.backend.sjs.JSCodeGen.run(JSCodeGen.scala:163)
[error] dotty.tools.backend.sjs.GenSJSIR.run(GenSJSIR.scala:18)
[error] dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:327)
[error] scala.collection.immutable.List.map(List.scala:250)
[error] dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:331)
[error] dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:246)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1321)
[error] dotty.tools.dotc.Run.runPhases$1(Run.scala:262)
[error] dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:270)
[error] dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:279)
[error] dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67)
[error] dotty.tools.dotc.Run.compileUnits(Run.scala:279)
[error] dotty.tools.dotc.Run.compileSources(Run.scala:194)
[error] dotty.tools.dotc.Run.compile(Run.scala:179)
[error] dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
[error] dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:88)
[error] dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22)
[error] sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:193)
[error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
[error] sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:248)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:183)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:163)
[error] sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:163)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:211)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:534)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:534)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:180)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:178)
[error] sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:464)
[error] sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116)
[error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56)
[error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52)
[error] sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:263)
[error] sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:419)
[error] sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:506)
[error] sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:406)
[error] sbt.internal.inc.Incremental$.apply(Incremental.scala:172)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:534)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:488)
[error] sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:425)
[error] sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137)
[error] sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2371)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2321)
[error] sbt.internal.server.BspCompileTask$.$anonfun$compute$1(BspCompileTask.scala:31)
[error] sbt.internal.io.Retry$.apply(Retry.scala:47)
[error] sbt.internal.io.Retry$.apply(Retry.scala:29)
[error] sbt.internal.io.Retry$.apply(Retry.scala:24)
[error] sbt.internal.server.BspCompileTask$.compute(BspCompileTask.scala:31)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:2319)
[error] scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error] sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:63)
[error] sbt.std.Transform$$anon$4.work(Transform.scala:69)
[error] sbt.Execute.$anonfun$submit$2(Execute.scala:283)
[error] sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:24)
[error] sbt.Execute.work(Execute.scala:292)
[error] sbt.Execute.$anonfun$submit$1(Execute.scala:283)
[error] sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error] sbt.CompletionService$$anon$2.call(CompletionService.scala:65)
[error] java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
[error] java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
[error] java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
[error] java.base/java.lang.Thread.run(Thread.java:833)
[error]
[error] stack trace is suppressed; run last frontend / Compile / compileIncremental for the full output
[error] (frontend / Compile / compileIncremental) scala.MatchError: AppliedType(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),class Tuple2),List(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),class Int), TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),class Int))) (of class dotty.tools.dotc.core.Types$CachedAppliedType)
[error] Total time: 2 s, completed Oct. 6, 2023, 12:16:44 a.m.

Expectation

The compiler shouldn't crash.

@raquo raquo added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Oct 6, 2023
@sjrd sjrd self-assigned this Oct 6, 2023
@sjrd sjrd added area:scala.js and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Oct 6, 2023
@sjrd sjrd changed the title Scala 3 compiler crashes on certain overloaded methods on JS classes Scala 3 compiler crashes on overloaded methods with varargs of generic types on JS classes Oct 6, 2023
@sjrd sjrd changed the title Scala 3 compiler crashes on overloaded methods with varargs of generic types on JS classes Compiler crashes on overloaded methods with varargs of generic types on JS classes Oct 6, 2023
sjrd added a commit to dotty-staging/dotty that referenced this issue Oct 6, 2023
When extracting the type of a varargs parameter, we have to go back
to before erasure. However, that gives us a non-erased type inside
as well. We need to re-erase that type to get something sensible
for the back-end.
sjrd added a commit to dotty-staging/dotty that referenced this issue Oct 6, 2023
When extracting the type of a varargs parameter, we have to go back
to before erasure. However, that gives us a non-erased type inside
as well. We need to re-erase that type to get something sensible
for the back-end.
sjrd added a commit to dotty-staging/dotty that referenced this issue Oct 6, 2023
When extracting the type of a varargs parameter, we have to go back
to before erasure. However, that gives us a non-erased type inside
as well. We need to re-erase that type to get something sensible
for the back-end.
@sjrd
Copy link
Member

sjrd commented Oct 6, 2023

Thanks for the report. PR at #18659.

@sjrd sjrd linked a pull request Oct 6, 2023 that will close this issue
sjrd added a commit to dotty-staging/dotty that referenced this issue Oct 11, 2023
When extracting the type of a varargs parameter, we have to go back
to before erasure. However, that gives us a non-erased type inside
as well. We need to re-erase that type to get something sensible
for the back-end.
sjrd added a commit to dotty-staging/dotty that referenced this issue Oct 12, 2023
When extracting the type of a varargs parameter, we have to go back
to before erasure. However, that gives us a non-erased type inside
as well. We need to re-erase that type to get something sensible
for the back-end.
nicolasstucki added a commit that referenced this issue Oct 16, 2023
When extracting the type of a varargs parameter, we have to go back to
before erasure. However, that gives us a non-erased type inside as well.
We need to re-erase that type to get something sensible for the
back-end.
nicolasstucki pushed a commit to dotty-staging/dotty that referenced this issue Oct 19, 2023
When extracting the type of a varargs parameter, we have to go back
to before erasure. However, that gives us a non-erased type inside
as well. We need to re-erase that type to get something sensible
for the back-end.
WojciechMazur pushed a commit that referenced this issue Jun 21, 2024
When extracting the type of a varargs parameter, we have to go back
to before erasure. However, that gives us a non-erased type inside
as well. We need to re-erase that type to get something sensible
for the back-end.

[Cherry-picked 4538875]
WojciechMazur added a commit that referenced this issue Jun 22, 2024
…n`." to LTS (#20713)

Backports #18659 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants