Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Crashes when defining a polymorphic function with by name parameters: assertion failed: Not a valid PolyFunction refinement #21652

Closed
Atry opened this issue Sep 26, 2024 · 1 comment · Fixed by #21671
Assignees
Labels
area:polyfunction area:typer itype:bug itype:crash regression This worked in a previous version but doesn't anymore
Milestone

Comments

@Atry
Copy link
Contributor

Atry commented Sep 26, 2024

Compiler version

3.5.1

Minimized code

def k: [A] => (=> A) => [B] => (=> B) => A = { [A] => a => [B] => b =>
  lazy val lazyA = a
  lazyA
}

Output (click arrow to expand)

[info] compiling 1 Scala source to /home/nixos/m-combinator.scala/target/scala-3.5.1/classes ...
[info] 
[info]   exception occurred while typechecking /home/nixos/m-combinator.scala/M.scala
[info] 
[info]   An unhandled exception was thrown in the compiler.
[info]   Please file a crash report here:
[info]   https://github.com/scala/scala3/issues/new/choose
[info]   For non-enriched exceptions, compile with -Xno-enrich-error-messages.
[info] 
[info]      while compiling: /home/nixos/m-combinator.scala/M.scala
[info]         during phase: typer
[info]                 mode: Mode(ImplicitsEnabled)
[info]      library version: version 2.13.14
[info]     compiler version: version 3.5.1
[info]             settings: -classpath /home/nixos/m-combinator.scala/target/scala-3.5.1/classes:/home/nixos/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.5.1/scala3-library_3-3.5.1.jar:/home/nixos/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.14/scala-library-2.13.14.jar -d /home/nixos/m-combinator.scala/target/scala-3.5.1/classes
[error] ## Exception when compiling 1 sources to /home/nixos/m-combinator.scala/target/scala-3.5.1/classes
[error] java.lang.AssertionError: assertion failed: Not a valid PolyFunction refinement: PolyType(List(B), List(TypeBounds(TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Nothing),TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Any))), MethodType(List(b), List(ExprType(TypeParamRef(B))), TypeRef(NoPrefix,type A)))
[error] scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
[error] dotty.tools.dotc.core.Definitions$PolyFunctionOf$.apply(Definitions.scala:1205)
[error] dotty.tools.dotc.core.Types$Type.toFunctionType(Types.scala:1978)
[error] dotty.tools.dotc.typer.TypeAssigner.assignType(TypeAssigner.scala:425)
[error] dotty.tools.dotc.typer.TypeAssigner.assignType$(TypeAssigner.scala:16)
[error] dotty.tools.dotc.typer.Typer.assignType(Typer.scala:145)
[error] dotty.tools.dotc.typer.Typer.typedClosure(Typer.scala:1973)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3426)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3499)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3576)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3580)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3691)
[error] dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1406)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3422)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3499)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3576)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3580)
[error] dotty.tools.dotc.typer.Typer.typedPolyFunctionValue(Typer.scala:1923)
[error] dotty.tools.dotc.typer.Typer.typedPolyFunction(Typer.scala:1891)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3425)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3499)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3576)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3580)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3691)
[error] dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1406)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3422)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3499)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3576)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3580)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3691)
[error] dotty.tools.dotc.typer.Typer.$anonfun$64(Typer.scala:2838)
[error] dotty.tools.dotc.inlines.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:256)
[error] dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:2838)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3396)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3498)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3576)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3580)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3602)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3648)
[error] dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:1399)
[error] dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1403)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3422)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3499)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3576)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3580)
[error] dotty.tools.dotc.typer.Typer.typedPolyFunctionValue(Typer.scala:1923)
[error] dotty.tools.dotc.typer.Typer.typedPolyFunction(Typer.scala:1891)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3425)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3499)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3576)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3580)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3691)
[error] dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1406)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3422)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3499)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3576)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3580)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3691)
[error] dotty.tools.dotc.typer.Typer.$anonfun$64(Typer.scala:2838)
[error] dotty.tools.dotc.inlines.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:256)
[error] dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:2838)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3396)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3498)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3576)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3580)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3602)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3648)
[error] dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:3096)
[error] dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3402)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3406)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3498)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3576)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3580)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3602)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3648)
[error] dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:3229)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3448)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3499)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3576)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3580)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3691)
[error] dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:47)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:503)
[error] dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:53)
[error] dotty.tools.dotc.typer.TyperPhase.$anonfun$4(TyperPhase.scala:99)
[error] scala.collection.Iterator$$anon$6.hasNext(Iterator.scala:479)
[error] scala.collection.Iterator$$anon$9.hasNext(Iterator.scala:583)
[error] scala.collection.immutable.List.prependedAll(List.scala:152)
[error] scala.collection.immutable.List$.from(List.scala:685)
[error] scala.collection.immutable.List$.from(List.scala:682)
[error] scala.collection.IterableOps$WithFilter.map(Iterable.scala:900)
[error] dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:98)
[error] dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:343)
[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:1323)
[error] dotty.tools.dotc.Run.runPhases$1(Run.scala:336)
[error] dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:384)
[error] dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:396)
[error] dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69)
[error] dotty.tools.dotc.Run.compileUnits(Run.scala:396)
[error] dotty.tools.dotc.Run.compileSources(Run.scala:282)
[error] dotty.tools.dotc.Run.compile(Run.scala:267)
[error] dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
[error] dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:141)
[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:194)
[error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
[error] sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:249)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:184)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:164)
[error] sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:164)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:212)
[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$3(Incremental.scala:178)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$3$adapted(Incremental.scala:176)
[error] sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:454)
[error] sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:117)
[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:265)
[error] sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:409)
[error] sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:496)
[error] sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:396)
[error] sbt.internal.inc.Incremental$.apply(Incremental.scala:170)
[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:2427)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2377)
[error] sbt.internal.server.BspCompileTask$.$anonfun$compute$1(BspCompileTask.scala:41)
[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:41)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:2375)
[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:317)
[error] java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572)
[error] java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
[error] java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
[error] java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
[error] java.base/java.lang.Thread.run(Thread.java:1583)
[error]            
[error] stack trace is suppressed; run last Compile / compileIncremental for the full output
[error] (Compile / compileIncremental) java.lang.AssertionError: assertion failed: Not a valid PolyFunction refinement: PolyType(List(B), List(TypeBounds(TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Nothing),TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Any))), MethodType(List(b), List(ExprType(TypeParamRef(B))), TypeRef(NoPrefix,type A)))
[error] Total time: 0 s, completed Sep 26, 2024, 5:27:02 PM
@Atry Atry added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 26, 2024
@Gedochao
Copy link
Contributor

Do note that it doesn't crash in LTS, returning a valid (?) error (with Scala 3.3.4 and 3.3.5-RC1-bin-20240925-9eb858b-NIGHTLY):

-- Error: /Users/pchabelski/IdeaProjects/scala-cli-tests-2/untitled/compiler-repro/repro.scala:1:54 
1 |def k: [A] => (=> A) => [B] => (=> B) => A = { [A] => a => [B] => b =>
  |                                                      ^
  |                 cannot infer type; expected type <?> is not fully defined
1 error found
Compilation failed

crashes on 3.4.0+

@Gedochao Gedochao added area:typer and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 27, 2024
@Atry Atry changed the title Crash when defining a polymorphic function with by name parameter: assertion failed: Not a valid PolyFunction refinement Crashes when defining a polymorphic function with by name parameters: assertion failed: Not a valid PolyFunction refinement Sep 27, 2024
@Gedochao Gedochao added area:polyfunction regression This worked in a previous version but doesn't anymore labels Sep 27, 2024
@WojciechMazur WojciechMazur added this to the 3.6.0 milestone Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:polyfunction area:typer itype:bug itype:crash regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants