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

Compiler crash with recursive match type #15352

Closed
cayhorstmann opened this issue Jun 1, 2022 · 0 comments · Fixed by #15423
Closed

Compiler crash with recursive match type #15352

cayhorstmann opened this issue Jun 1, 2022 · 0 comments · Fixed by #15423

Comments

@cayhorstmann
Copy link

Compiler version

3.1.2

Minimized code

import scala.compiletime.*
import scala.compiletime.ops.int.*

abstract sealed class HList :
  def ::[H](head: H): HNonEmpty[H, this.type] = HNonEmpty(head, this)

case object HNil extends HList
case class HNonEmpty[H, T <: HList](head: H, tail: T) extends HList :  
  type Elem[N <: Int] =
    N match 
      case 0 => H 
      case S[n1] => Elem[n1]
      
  inline def apply[N <: Int](n: N): Elem[N] = 
    n match 
      case _: 0 => head
      case _: S[n1] => tail.asInstanceOf[HNonEmpty[?, ?]].apply(constValue[n1])

Output (click arrow to expand)

scala.MatchError: Range(AppliedType(TypeRef(ThisType(TypeRef(NoPrefix,module class runtime)),class MatchCase),List(ConstantType(Constant(0)), TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Nothing))),AppliedType(TypeRef(ThisType(TypeRef(NoPrefix,module class runtime)),class MatchCase),List(ConstantType(Constant(0)), TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Any)))) (of class dotty.tools.dotc.core.Types$Range)
	at dotty.tools.dotc.core.TrackingTypeComparer.matchCase$1(TypeComparer.scala:2883)
	at dotty.tools.dotc.core.TrackingTypeComparer.recur$2(TypeComparer.scala:2906)
	at dotty.tools.dotc.core.TrackingTypeComparer.op$proxy70$1(TypeComparer.scala:2936)
	at dotty.tools.dotc.core.TrackingTypeComparer.matchCases(TypeComparer.scala:2937)
	at dotty.tools.dotc.core.Types$MatchType.matchCases$1(Types.scala:4852)
	at dotty.tools.dotc.core.Types$MatchType.reduced$$anonfun$1(Types.scala:4861)
	at dotty.tools.dotc.core.TypeComparer.inSubComparer(TypeComparer.scala:2646)
	at dotty.tools.dotc.core.TypeComparer.tracked(TypeComparer.scala:2656)
	at dotty.tools.dotc.core.TypeComparer$.tracked(TypeComparer.scala:2809)
	at dotty.tools.dotc.core.Types$MatchType.reduced(Types.scala:4861)
	at dotty.tools.dotc.core.Types$MatchType.tryNormalize(Types.scala:4810)
	at dotty.tools.dotc.core.Types$Type.normalized(Types.scala:1425)
	at dotty.tools.dotc.core.Types$AppliedType.superType(Types.scala:4145)
	at dotty.tools.dotc.core.TypeComparer.compareAppliedType1$1(TypeComparer.scala:1231)
	at dotty.tools.dotc.core.TypeComparer.fourthTry$1(TypeComparer.scala:782)
	at dotty.tools.dotc.core.TypeComparer.fallback$2$$anonfun$1(TypeComparer.scala:1146)
	at scala.Function0.apply$mcZ$sp(Function0.scala:39)
	at dotty.tools.dotc.core.TypeComparer.necessaryEither(TypeComparer.scala:1702)
	at dotty.tools.dotc.core.TypeComparer.either(TypeComparer.scala:1581)
	at dotty.tools.dotc.core.TypeComparer.fallback$2(TypeComparer.scala:1146)
	at dotty.tools.dotc.core.TypeComparer.compareLower$1(TypeComparer.scala:1162)
	at dotty.tools.dotc.core.TypeComparer.compareAppliedType2$1(TypeComparer.scala:1186)
	at dotty.tools.dotc.core.TypeComparer.thirdTry$1(TypeComparer.scala:559)
	at dotty.tools.dotc.core.TypeComparer.secondTry$1(TypeComparer.scala:492)
	at dotty.tools.dotc.core.TypeComparer.firstTry$1(TypeComparer.scala:378)
	at dotty.tools.dotc.core.TypeComparer.recur(TypeComparer.scala:1309)
	at dotty.tools.dotc.core.TypeComparer.firstTry$1(TypeComparer.scala:321)
	at dotty.tools.dotc.core.TypeComparer.recur(TypeComparer.scala:1309)
	at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:189)
	at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:199)
	at dotty.tools.dotc.core.TypeComparer.topLevelSubType(TypeComparer.scala:126)
	at dotty.tools.dotc.core.TypeComparer.necessarySubType(TypeComparer.scala:137)
	at dotty.tools.dotc.core.TypeComparer$.necessarySubType(TypeComparer.scala:2712)
	at dotty.tools.dotc.typer.ProtoTypes$Compatibility.necessarilyCompatible(ProtoTypes.scala:47)
	at dotty.tools.dotc.typer.ProtoTypes$Compatibility.necessarilyCompatible$(ProtoTypes.scala:26)
	at dotty.tools.dotc.typer.Typer.necessarilyCompatible(Typer.scala:119)
	at dotty.tools.dotc.typer.ProtoTypes$Compatibility.constrainResult(ProtoTypes.scala:97)
	at dotty.tools.dotc.typer.ProtoTypes$Compatibility.constrainResult$(ProtoTypes.scala:26)
	at dotty.tools.dotc.typer.Typer.constrainResult(Typer.scala:119)
	at dotty.tools.dotc.typer.ProtoTypes$Compatibility.constrainResult(ProtoTypes.scala:117)
	at dotty.tools.dotc.typer.ProtoTypes$Compatibility.constrainResult$(ProtoTypes.scala:26)
	at dotty.tools.dotc.typer.Typer.constrainResult(Typer.scala:119)
	at dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:438)
	at dotty.tools.dotc.typer.Applications$TypedApply.<init>(Applications.scala:735)
	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.<init>(Applications.scala:852)
	at dotty.tools.dotc.typer.Applications.ApplyTo(Applications.scala:1052)
	at dotty.tools.dotc.typer.Applications.ApplyTo$(Applications.scala:317)
	at dotty.tools.dotc.typer.Typer.ApplyTo(Typer.scala:119)
	at dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:898)
	at dotty.tools.dotc.typer.Applications.realApply$1$$anonfun$3(Applications.scala:978)
	at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:3081)
	at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:989)
	at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1027)
	at dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:317)
	at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:119)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2809)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2872)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2937)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2941)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3057)
	at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1075)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2817)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2872)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2937)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2941)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3057)
	at dotty.tools.dotc.typer.Typer.caseRest$1(Typer.scala:1684)
	at dotty.tools.dotc.typer.Typer.typedCase(Typer.scala:1700)
	at dotty.tools.dotc.typer.Typer.$anonfun$24(Typer.scala:1612)
	at scala.collection.immutable.List.map(List.scala:250)
	at dotty.tools.dotc.typer.Typer.typedDependentMatchFinish(Typer.scala:1615)
	at dotty.tools.dotc.typer.Typer.typedMatch(Typer.scala:1576)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2823)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2872)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2937)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2941)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3057)
	at dotty.tools.dotc.typer.Typer.$anonfun$47(Typer.scala:2256)
	at dotty.tools.dotc.typer.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:238)
	at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:2256)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2786)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2871)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2937)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2941)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2963)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3013)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2454)
	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:2797)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2801)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2871)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2937)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2941)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2963)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3013)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2454)
	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:2797)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2801)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2871)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2937)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2941)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2963)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3013)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2581)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2842)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2872)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2937)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2941)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3057)
	at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:47)
	at dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:411)
	at dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:54)
	at dotty.tools.dotc.typer.TyperPhase.runOn$$anonfun$3(TyperPhase.scala:88)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:333)
	at dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:88)
	at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:259)
	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:1328)
	at dotty.tools.dotc.Run.runPhases$1(Run.scala:270)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:278)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:68)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:287)
	at dotty.tools.dotc.Run.compileSources(Run.scala:220)
	at dotty.tools.dotc.Run.compile(Run.scala:204)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:39)
	at dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:88)
	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:192)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
	at sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:247)
	at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:182)
	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:210)
	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:528)
	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:528)
	at sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:177)
	at sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:175)
	at sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:461)
	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:416)
	at sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:503)
	at sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:403)
	at sbt.internal.inc.Incremental$.apply(Incremental.scala:169)
	at sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:528)
	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:482)
	at sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332)
	at sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:420)
	at sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137)
	at sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2366)
	at sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2316)
	at sbt.internal.server.BspCompileTask$.$anonfun$compute$1(BspCompileTask.scala:30)
	at sbt.internal.io.Retry$.apply(Retry.scala:46)
	at sbt.internal.io.Retry$.apply(Retry.scala:28)
	at sbt.internal.io.Retry$.apply(Retry.scala:23)
	at sbt.internal.server.BspCompileTask$.compute(BspCompileTask.scala:30)
	at sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:2314)
	at scala.Function1.$anonfun$compose$1(Function1.scala:49)
	at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
	at sbt.std.Transform$$anon$4.work(Transform.scala:68)
	at sbt.Execute.$anonfun$submit$2(Execute.scala:282)
	at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
	at sbt.Execute.work(Execute.scala:291)
	at sbt.Execute.$anonfun$submit$1(Execute.scala:282)
	at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
	at sbt.CompletionService$$anon$2.call(CompletionService.scala:64)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:831)
@cayhorstmann cayhorstmann added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 1, 2022
@anatoliykmetyuk anatoliykmetyuk added area:match-types and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 10, 2022
@Kordyjan Kordyjan added this to the 3.2.1 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants