ScalablyTyped/Converter

Exception when migrating from scala 3.1.3 to 3.2.0

ylaurent opened this issue ยท 10 comments

Hello,
First i want to say im very thankful for scalablytyped, it is amazing and I am having a blast using it :)
Back to the issue:
When updating scala version to 3.2.0 (and using scalajs 1.11.0 / sbt-converter 1.0.0-beta39), it seems the compiler is now throwing an exception when compiling lightweight-charts

Compile / npmDependencies ++= Seq("lightweight-charts" -> "3.8.0")
[warn] Phase1ReadTypescript.scala:204  Processing lightweight-charts [thread => 1193, project => frontend, ms => 10389, path => /Users/[...]/frontend/target/scala-3.2.0/scalajs-bundler/main/node_modules/lightweight-charts, phase => typescript, id => lightweight-charts]
[warn] Phase2ToScalaJs.scala:64  Processing std [thread => 1193, project => frontend, ms => 11433, phase => scala.js, id => std]
[warn] Phase2ToScalaJs.scala:64  Processing lightweight-charts [thread => 1193, project => frontend, ms => 23106, phase => scala.js, id => lightweight-charts]
[warn] Phase3Compile.scala:107  Using cached build /Users/[...]/.ivy2/local/org.scalablytyped/std_sjs1_3/4.3-61dfef/jars/std_sjs1_3.jar [thread => 1193, project => frontend, ms => 25507, phase => build, id => std, flavour => NormalFlavour]
[warn] Phase3Compile.scala:123  Building /Users/[...]/.ivy2/local/org.scalablytyped/lightweight-charts_sjs1_3/3.8.0-97291d/jars/lightweight-charts_sjs1_3.jar... [thread => 1193, project => frontend, ms => 25684, phase => build, id => lightweight-charts, flavour => NormalFlavour]
[info] ZincCompiler.scala:234 msg.get() compiling 107 Scala sources to /Users/[...]/frontend/target/streams/_global/stImport/_global/streams/sources/l/lightweight-charts/target/scala-3/classes ... [project => frontend, ms => 25553]
[info] ZincCompiler.scala:234 msg.get() [Info] : exception occurred while typechecking /Users/[...]/frontend/target/streams/_global/stImport/_global/streams/sources/l/lightweight-charts/src/main/scala/typings/lightweightCharts/mod/ISeriesApi.scala [project => frontend, ms => 26326]
[info] ZincCompiler.scala:234 msg.get() [Info] : exception occurred while compiling [...]
java.lang.AssertionError: assertion failed: <notype> & <notype> / NoType & NoType while compiling [...]
[error] ZincCompiler.scala:230 msg.get() ## Exception when compiling 107 sources to /Users/[...]/frontend/target/streams/_global/stImport/_global/streams/sources/l/lightweight-charts/target/scala-3/classes
[error] java.lang.AssertionError: assertion failed: <notype> & <notype> / NoType & NoType
[error] scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
[error] dotty.tools.dotc.core.Types$AndType$.apply(Types.scala:3203)
[error] dotty.tools.dotc.core.TypeOps$.approximateOr$1$$anonfun$2(TypeOps.scala:352)
[error] scala.collection.IterableOnceOps.reduceLeft(IterableOnce.scala:738)
[error] scala.collection.IterableOnceOps.reduceLeft$(IterableOnce.scala:724)
[error] scala.collection.AbstractIterable.reduceLeft(Iterable.scala:926)
[error] dotty.tools.dotc.core.TypeOps$.approximateOr$1(TypeOps.scala:352)
[error] dotty.tools.dotc.core.TypeOps$.orDominator(TypeOps.scala:362)
[...]
[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]             [project => frontend, ms => 26341]
[error] PhaseRes.scala:78  Caught exception: assertion failed: <notype> & <notype> / NoType & NoType [thread => 1193, project => frontend, ms => 26544, phase => build, id => lightweight-charts]java.lang.AssertionError: assertion failed: <notype> & <notype> / NoType & NoType
[error] 	at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
[error] 	at dotty.tools.dotc.core.Types$AndType$.apply(Types.scala:3203)
[...]

So seems to be java.lang.AssertionError: assertion failed: <notype> & <notype> / NoType & NoType type of exception, any idea? Is 3.2.0 not yet supported and it is better to not update yet?

Hey there, thanks for the report.

This is likely ST producing some semi bogus intersection type, which in turn causes scala 3 to throw this error. I've seen it before with earlier versions of scala 3, back then it was something like String & Object. The solution then was to make ST not do that, which isn't too hard. Just got to figure what it is first.

What I did last time was to debug the compiler and see which type it was working on.

I haven't had time to update to 3.2 and test it yet, though i haven't heard anything until now that it isn't working

I see. Yeah scala 3.2.0 just released so probably not many project upgraded yet.

I created a reduced reproducer here https://github.com/ylaurent/scalablytyped-lightweightchart similar to another issue I saw in the issue list. Just doing sbt compile show the issue.

At least now i know its not some kind of configuration I am missing

Towards a smaller repro. Changing this line: type Nominal[T, Name /* <: String */] = T & Species[Name] to type Nominal[T, Name /* <: String */] = Any makes it compile.

Species refers to this:

@js.native
trait Species[Name /* <: String */] extends StObject {
  
  /** The 'name' or species of the nominal. */
  @JSName(js.Symbol.species)
  var species: Name = js.native
}

However, the exception is not triggered by only those lines, there is something else in the generated code which needs to be present as well.

Swapping the order to type Nominal[T, Name /* <: String */] = Species[Name] & T also makes it compile.

oh nice, glad that there is a solution to the issue :)

I managed to minimize it in the end in scala/scala3#16236 .

thats amazing ๐Ÿ™ , looking forward to what they will say ๐Ÿ‘Œ

I think this should be fixed with 3.2.1 :)

yes, I saw the fix merged on dotty repo, its amazing how fast they addressed and fixed the issue ๐Ÿ‘Œ props as well to @oyvindberg that took time to investigate and minimize the issue :) ๐Ÿ‘

Issue is fixed with 3.2.1 ; closing the issue, thanks @oyvindberg ๐Ÿ‘Œ