Skip to content

Any capturing function type immediately after a type abstraction crashes the compiler #18518

@Linyxus

Description

@Linyxus

Compiler version

main

Minimized code

import language.experimental.captureChecking
type Foo1 = [R] -> (x: Unit) ->{} Unit  // crashes
// Or the following variants ...
// type Foo2 = [R] -> (x: Unit) ->{cap} Unit
// type Foo3 = (c: Int^) -> [R] -> (x: Unit) ->{c} Unit

// but the following works
type Foo4 = (c: Int^) -> [R] -> (x0: Unit) -> (x: Unit) ->{c} Unit  // ok

Output (click arrow to expand)

  exception occurred while typechecking issues/cc-lambda-types.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: issues/cc-lambda-types.scala
        during phase: typer
                mode: Mode(ImplicitsEnabled)
     library version: version 2.13.10
    compiler version: version 3.4.0-RC1-bin-SNAPSHOT-nonbootstrapped-git-6dc3737
            settings: -classpath /Users/linyxus/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.10/scala-library-2.13.10.jar:/Users/linyxus/Workspace/dotty/library/../out/bootstrap/scala3-library-bootstrapped/scala-3.4.0-RC1-bin-SNAPSHOT-nonbootstrapped/scala3-library_3-3.4.0-RC1-bin-SNAPSHOT.jar -color never

                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 ==


Exception in thread "main" scala.MatchError: CapturesAndResult(List(),Ident(Unit)) (of class dotty.tools.dotc.ast.untpd$CapturesAndResult)
	at dotty.tools.dotc.ast.desugar$.apply(Desugar.scala:1873)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3161)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3179)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3255)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3259)
	at dotty.tools.dotc.typer.Typer.typedType(Typer.scala:3374)
	at dotty.tools.dotc.typer.Namer.typedAheadType$$anonfun$1(Namer.scala:1655)
	at dotty.tools.dotc.typer.Namer.typedAhead(Namer.scala:1648)
	at dotty.tools.dotc.typer.Namer.typedAheadType(Namer.scala:1655)
	at dotty.tools.dotc.typer.Namer.valOrDefDefSig(Namer.scala:1749)
	at dotty.tools.dotc.typer.Namer.defDefSig(Namer.scala:1800)
	at dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:793)
	at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:936)
	at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:816)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:174)
	at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:187)
	at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:189)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:393)
	at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:3052)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3077)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3178)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3255)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3259)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3281)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3327)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2738)
	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3099)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3103)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3178)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3255)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3259)
	at dotty.tools.dotc.typer.Typer.typedRefinedTypeTree(Typer.scala:2149)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3137)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3179)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3255)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3259)
	at dotty.tools.dotc.typer.Typer.typedPolyFunction(Typer.scala:1648)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3122)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3179)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3255)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3259)
	at dotty.tools.dotc.typer.Typer.typedType(Typer.scala:3374)
	at dotty.tools.dotc.typer.Namer.typedAheadType$$anonfun$1(Namer.scala:1655)
	at dotty.tools.dotc.typer.Namer.typedAhead(Namer.scala:1648)
	at dotty.tools.dotc.typer.Namer.typedAheadType(Namer.scala:1655)
	at dotty.tools.dotc.typer.Namer$TypeDefCompleter.typeSig(Namer.scala:1035)
	at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:936)
	at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:816)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:174)
	at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:187)
	at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:189)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:393)
	at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:3052)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3077)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3178)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3255)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3259)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3281)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3327)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2738)
	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3099)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3103)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3178)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3255)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3259)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3281)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3327)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2873)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3145)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3179)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3255)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3259)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3371)
	at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:44)
	at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$adapted$1(TyperPhase.scala:50)
	at scala.Function0.apply$mcV$sp(Function0.scala:42)
	at dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:440)
	at dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:50)
	at dotty.tools.dotc.typer.TyperPhase.runOn$$anonfun$3(TyperPhase.scala:84)
	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:84)
	at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:246)
	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:1321)
	at dotty.tools.dotc.Run.runPhases$1(Run.scala:262)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:270)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:279)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:71)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:279)
	at dotty.tools.dotc.Run.compileSources(Run.scala:194)
	at dotty.tools.dotc.Run.compile(Run.scala:179)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
	at dotty.tools.dotc.Driver.process(Driver.scala:197)
	at dotty.tools.dotc.Driver.process(Driver.scala:165)
	at dotty.tools.dotc.Driver.process(Driver.scala:177)
	at dotty.tools.dotc.Driver.main(Driver.scala:207)
	at dotty.tools.dotc.Main.main(Main.scala)
[error] Nonzero exit code returned from runner: 1
[error] (scala3-compiler / Compile / runMain) Nonzero exit code returned from runner: 1
[error] Total time: 1 s, completed Sep 6, 2023, 1:46:51 AM

Metadata

Metadata

Assignees

No one assigned

    Labels

    cc-experimentIntended to be merged with cc-experiment branch on originitype:bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions