scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.88k stars 1.06k forks source link

Dotty crashes when defined a Polymorphic function type value with a By-Name parameter. #21713

Closed RayStarkMC closed 1 month ago

RayStarkMC commented 1 month ago

Compiler version

3.5.2-RC1

Minimized code

val a: [A] => (=> A) => Unit = [A] => a => ()

Output (click arrow to expand)

```text java.lang.AssertionError: assertion failed: Not a valid PolyFunction refinement: PolyType(List(A), List(TypeBounds(TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Nothing),TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Any))), MethodType(List(a), List(ExprType(TypeParamRef(A))), TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),class Unit))) at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8) at dotty.tools.dotc.core.Definitions$PolyFunctionOf$.apply(Definitions.scala:1205) at dotty.tools.dotc.core.Types$Type.toFunctionType(Types.scala:1979) at dotty.tools.dotc.typer.TypeAssigner.assignType(TypeAssigner.scala:425) at dotty.tools.dotc.typer.TypeAssigner.assignType$(TypeAssigner.scala:16) at dotty.tools.dotc.typer.Typer.assignType(Typer.scala:145) at dotty.tools.dotc.typer.Typer.typedClosure(Typer.scala:1975) at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3427) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3500) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3577) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3581) at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3692) at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1406) at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3423) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3500) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3577) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3581) at dotty.tools.dotc.typer.Typer.typedPolyFunctionValue(Typer.scala:1917) at dotty.tools.dotc.typer.Typer.typedPolyFunction(Typer.scala:1891) at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3426) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3500) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3577) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3581) at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3692) at dotty.tools.dotc.typer.Typer.typedValDef(Typer.scala:2771) at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3394) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3499) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3577) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3581) at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3603) at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3649) at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:3097) at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3403) at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3407) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3499) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3577) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3581) at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3603) at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3649) at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:3230) at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3449) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3500) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3577) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3581) at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3692) at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:47) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10) at dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:503) at dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:53) at dotty.tools.dotc.typer.TyperPhase.$anonfun$4(TyperPhase.scala:99) at scala.collection.Iterator$$anon$6.hasNext(Iterator.scala:479) at scala.collection.Iterator$$anon$9.hasNext(Iterator.scala:583) at scala.collection.immutable.List.prependedAll(List.scala:152) at scala.collection.immutable.List$.from(List.scala:685) at scala.collection.immutable.List$.from(List.scala:682) at scala.collection.IterableOps$WithFilter.map(Iterable.scala:900) at dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:98) at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:343) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10) at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323) at dotty.tools.dotc.Run.runPhases$1(Run.scala:336) at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:384) at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:396) at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69) at dotty.tools.dotc.Run.compileUnits(Run.scala:396) at dotty.tools.dotc.Run.compileSources(Run.scala:282) at dotty.tools.dotc.Run.compile(Run.scala:267) at dotty.tools.dotc.Driver.doCompile(Driver.scala:37) at dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:141) at dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22) at sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91) at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:193) at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23) at sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:248) at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:183) at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:163) at sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239) at sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:163) at sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:211) at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:534) at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:534) at sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:180) at sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:178) at sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:464) at sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116) at sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56) at sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52) at sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:263) at sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:419) at sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:506) at sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:406) at sbt.internal.inc.Incremental$.apply(Incremental.scala:172) at sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:534) at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:488) at sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332) at sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:425) at sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137) at sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2371) at sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2321) at sbt.internal.server.BspCompileTask$.$anonfun$compute$1(BspCompileTask.scala:31) at sbt.internal.io.Retry$.apply(Retry.scala:47) at sbt.internal.io.Retry$.apply(Retry.scala:29) at sbt.internal.io.Retry$.apply(Retry.scala:24) at sbt.internal.server.BspCompileTask$.compute(BspCompileTask.scala:31) at sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:2319) at scala.Function1.$anonfun$compose$1(Function1.scala:49) at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:63) at sbt.std.Transform$$anon$4.work(Transform.scala:69) at sbt.Execute.$anonfun$submit$2(Execute.scala:283) at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:24) at sbt.Execute.work(Execute.scala:292) at sbt.Execute.$anonfun$submit$1(Execute.scala:283) at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265) at sbt.CompletionService$$anon$2.call(CompletionService.scala:65) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) at java.base/java.lang.Thread.run(Thread.java:840) ```
RayStarkMC commented 1 month ago

(Translated by MT.)

I found a duplicate issue with this issue and will close it.

My apologies.

https://github.com/scala/scala3/issues/21652