Skip to content

Assertion failure "attempted to take ownership of" #23751

@eejbyfeldt

Description

@eejbyfeldt

Compiler version

3.7.2

Minimized code

trait TC[X]

object TC {
  given t2[T]: TC[T] = ???
  given t1[T]: TC[T] = ???
}

class Seq2[T] {
  def map[U](f: T => U): Seq2[U] = ???
  def sorted(using TC[T]): Seq2[T] = ???
}

def testJob(args: Any): Unit = ???

def sink[M](verifier: Seq2[M] => Any): Nothing = ???

object Crash {
  testJob(sink(_.map(r => ???).sorted ==== Seq2()))
}

Output (click arrow to expand)

  exception occurred while typechecking assert.scala

  An unhandled exception was thrown in the compiler.
  Please file a crash report here:
  https://github.com/scala/scala3/issues/new/choose
  For non-enriched exceptions, compile with -Xno-enrich-error-messages.


     while compiling: assert.scala
        during phase: typer
                mode: Mode(ImplicitsEnabled)
     library version: version 2.13.16
    compiler version: version 3.7.2
            settings: 

Exception in thread "main" java.lang.AssertionError: assertion failed: TS[1, 0] attempted to take ownership of M which is already owned by committable TS[12, 1, 0]
	at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
	at dotty.tools.dotc.core.TyperState.includeVar(TyperState.scala:273)
	at dotty.tools.dotc.core.TyperState.$anonfun$2$$anonfun$1(TyperState.scala:235)
	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:334)
	at dotty.tools.dotc.core.TyperState.$anonfun$2(TyperState.scala:234)
	at scala.collection.immutable.List.forall(List.scala:387)
	at dotty.tools.dotc.core.TyperState.mergeConstraintWith(TyperState.scala:229)
	at dotty.tools.dotc.typer.ProtoTypes$FunProto.typedArgs(ProtoTypes.scala:528)
	at dotty.tools.dotc.typer.ProtoTypes$FunProto.fold(ProtoTypes.scala:615)
	at dotty.tools.dotc.core.Types$TypeAccumulator.foldOver(Types.scala:6884)
	at dotty.tools.dotc.core.Types$TypeTraverser.traverseChildren(Types.scala:6922)
	at dotty.tools.dotc.typer.ImplicitRunInfo$collectParts$2$.traverse(Implicits.scala:682)
	at dotty.tools.dotc.core.Types$TypeTraverser.apply(Types.scala:6921)
	at dotty.tools.dotc.core.Types$TypeTraverser.apply(Types.scala:6921)
	at dotty.tools.dotc.typer.ProtoTypes$SelectionProto.fold(ProtoTypes.scala:281)
	at dotty.tools.dotc.core.Types$TypeAccumulator.foldOver(Types.scala:6884)
	at dotty.tools.dotc.core.Types$TypeTraverser.traverseChildren(Types.scala:6922)
	at dotty.tools.dotc.typer.ImplicitRunInfo$collectParts$2$.traverse(Implicits.scala:682)
	at dotty.tools.dotc.core.Types$TypeTraverser.apply(Types.scala:6921)
	at dotty.tools.dotc.core.Types$TypeTraverser.apply(Types.scala:6921)
	at dotty.tools.dotc.typer.ProtoTypes$ViewProto.fold(ProtoTypes.scala:672)
	at dotty.tools.dotc.core.Types$TypeAccumulator.foldOver(Types.scala:6884)
	at dotty.tools.dotc.core.Types$TypeTraverser.traverseChildren(Types.scala:6922)
	at dotty.tools.dotc.typer.ImplicitRunInfo$collectParts$2$.traverse(Implicits.scala:682)
	at dotty.tools.dotc.typer.ImplicitRunInfo$collectParts$2$.apply(Implicits.scala:688)
	at dotty.tools.dotc.typer.ImplicitRunInfo.recur$1(Implicits.scala:764)
	at dotty.tools.dotc.typer.ImplicitRunInfo.computeIScope(Implicits.scala:775)
	at dotty.tools.dotc.typer.ImplicitRunInfo.implicitScope(Implicits.scala:852)
	at dotty.tools.dotc.typer.ImplicitRunInfo.implicitScope$(Implicits.scala:626)
	at dotty.tools.dotc.Run.implicitScope(Run.scala:45)
	at dotty.tools.dotc.typer.Implicits$ImplicitSearch.implicitScope(Implicits.scala:1801)
	at dotty.tools.dotc.typer.Implicits$ImplicitSearch.searchImplicit(Implicits.scala:1683)
	at dotty.tools.dotc.typer.Implicits$ImplicitSearch.searchImplicit$$anonfun$3(Implicits.scala:1770)
	at dotty.tools.dotc.typer.Implicits$SearchResult.recoverWith(Implicits.scala:430)
	at dotty.tools.dotc.typer.Implicits$ImplicitSearch.searchImplicit(Implicits.scala:1756)
	at dotty.tools.dotc.typer.Implicits$ImplicitSearch.bestImplicit(Implicits.scala:1797)
	at dotty.tools.dotc.typer.Implicits.inferImplicit(Implicits.scala:1115)
	at dotty.tools.dotc.typer.Implicits.inferImplicit$(Implicits.scala:866)
	at dotty.tools.dotc.typer.Typer.inferImplicit(Typer.scala:155)
	at dotty.tools.dotc.typer.Implicits.inferView(Implicits.scala:906)
	at dotty.tools.dotc.typer.Implicits.inferView$(Implicits.scala:866)
	at dotty.tools.dotc.typer.Typer.inferView(Typer.scala:155)
	at dotty.tools.dotc.typer.Implicits.viewExists(Implicits.scala:879)
	at dotty.tools.dotc.typer.Implicits.viewExists$(Implicits.scala:866)
	at dotty.tools.dotc.typer.Typer.viewExists(Typer.scala:155)
	at dotty.tools.dotc.typer.ProtoTypes$Compatibility.necessarilyCompatible(ProtoTypes.scala:53)
	at dotty.tools.dotc.typer.ProtoTypes$Compatibility.necessarilyCompatible$(ProtoTypes.scala:32)
	at dotty.tools.dotc.typer.Typer.necessarilyCompatible(Typer.scala:155)
	at dotty.tools.dotc.typer.ProtoTypes$Compatibility.constrainResult(ProtoTypes.scala:104)
	at dotty.tools.dotc.typer.ProtoTypes$Compatibility.constrainResult$(ProtoTypes.scala:32)
	at dotty.tools.dotc.typer.Typer.constrainResult(Typer.scala:155)
	at dotty.tools.dotc.typer.ProtoTypes$Compatibility.constrainResult(ProtoTypes.scala:155)
	at dotty.tools.dotc.typer.ProtoTypes$Compatibility.constrainResult$(ProtoTypes.scala:32)
	at dotty.tools.dotc.typer.Typer.constrainResult(Typer.scala:155)
	at dotty.tools.dotc.typer.Typer.implicitArgs$1(Typer.scala:4342)
	at dotty.tools.dotc.typer.Typer.addImplicitArgs$1(Typer.scala:4404)
	at dotty.tools.dotc.typer.Typer.adaptNoArgsImplicitMethod$1(Typer.scala:4469)
	at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:4671)
	at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:4958)
	at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:4191)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3811)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3816)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3927)
	at dotty.tools.dotc.typer.Typer.typeSelectOnTerm$1(Typer.scala:1049)
	at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:1103)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3621)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3733)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3811)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3816)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3927)
	at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:1098)
	at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1299)
	at dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:470)
	at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:155)
	at dotty.tools.dotc.typer.Typer.typedInfixOp(Typer.scala:3520)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3687)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3734)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3811)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3816)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3927)
	at dotty.tools.dotc.typer.Typer.$anonfun$68(Typer.scala:2999)
	at dotty.tools.dotc.inlines.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:256)
	at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:2999)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3628)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3733)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3811)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3816)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3838)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3884)
	at dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:1504)
	at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1508)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3654)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3734)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3811)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3816)
	at dotty.tools.dotc.typer.Typer.typedFunctionValue(Typer.scala:1986)
	at dotty.tools.dotc.typer.Typer.typedFunction(Typer.scala:1723)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3656)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3734)
	at dotty.tools.dotc.typer.ProtoTypes$FunProto.$anonfun$7(ProtoTypes.scala:543)
	at dotty.tools.dotc.typer.ProtoTypes$FunProto.cacheTypedArg(ProtoTypes.scala:466)
	at dotty.tools.dotc.typer.ProtoTypes$FunProto.typedArg(ProtoTypes.scala:545)
	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:1054)
	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:1054)
	at dotty.tools.dotc.typer.Applications$Application.addTyped$1(Applications.scala:731)
	at dotty.tools.dotc.typer.Applications$Application.matchArgs(Applications.scala:803)
	at dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:610)
	at dotty.tools.dotc.typer.Applications$TypedApply.<init>(Applications.scala:929)
	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.<init>(Applications.scala:1053)
	at dotty.tools.dotc.typer.Applications.ApplyTo(Applications.scala:1325)
	at dotty.tools.dotc.typer.Applications.ApplyTo$(Applications.scala:470)
	at dotty.tools.dotc.typer.Typer.ApplyTo(Typer.scala:155)
	at dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:1126)
	at dotty.tools.dotc.typer.Applications.$anonfun$15(Applications.scala:1235)
	at dotty.tools.dotc.typer.Typer$.tryEither(Typer.scala:128)
	at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:1250)
	at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1299)
	at dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:470)
	at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:155)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3646)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3734)
	at dotty.tools.dotc.typer.ProtoTypes$FunProto.$anonfun$7(ProtoTypes.scala:543)
	at dotty.tools.dotc.typer.ProtoTypes$FunProto.cacheTypedArg(ProtoTypes.scala:466)
	at dotty.tools.dotc.typer.ProtoTypes$FunProto.typedArg(ProtoTypes.scala:545)
	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:1054)
	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:1054)
	at dotty.tools.dotc.typer.Applications$Application.addTyped$1(Applications.scala:731)
	at dotty.tools.dotc.typer.Applications$Application.matchArgs(Applications.scala:803)
	at dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:610)
	at dotty.tools.dotc.typer.Applications$TypedApply.<init>(Applications.scala:929)
	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.<init>(Applications.scala:1053)
	at dotty.tools.dotc.typer.Applications.ApplyTo(Applications.scala:1325)
	at dotty.tools.dotc.typer.Applications.ApplyTo$(Applications.scala:470)
	at dotty.tools.dotc.typer.Typer.ApplyTo(Typer.scala:155)
	at dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:1126)
	at dotty.tools.dotc.typer.Applications.$anonfun$15(Applications.scala:1235)
	at dotty.tools.dotc.typer.Typer$.tryEither(Typer.scala:128)
	at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:1250)
	at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1299)
	at dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:470)
	at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:155)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3646)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3734)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3811)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3816)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3865)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3884)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:3303)
	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3634)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3638)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3733)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3811)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3816)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3838)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3884)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:3436)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3680)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3734)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3811)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3816)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3927)
	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:510)
	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:368)
	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:1324)
	at dotty.tools.dotc.Run.runPhases$1(Run.scala:361)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1$$anonfun$2(Run.scala:408)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1$$anonfun$adapted$1(Run.scala:408)
	at scala.Function0.apply$mcV$sp(Function0.scala:42)
	at dotty.tools.dotc.Run.showProgress(Run.scala:470)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:408)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:420)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:420)
	at dotty.tools.dotc.Run.compileSources(Run.scala:307)
	at dotty.tools.dotc.Run.compile(Run.scala:292)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
	at dotty.tools.dotc.Driver.process(Driver.scala:201)
	at dotty.tools.dotc.Driver.process(Driver.scala:169)
	at dotty.tools.dotc.Driver.process(Driver.scala:181)
	at dotty.tools.dotc.Driver.main(Driver.scala:211)
	at dotty.tools.MainGenericCompiler$.run$1(MainGenericCompiler.scala:160)
	at dotty.tools.MainGenericCompiler$.main(MainGenericCompiler.scala:184)
	at dotty.tools.MainGenericCompiler.main(MainGenericCompiler.scala)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at coursier.bootstrap.launcher.a.a(Unknown Source)
	at coursier.bootstrap.launcher.Launcher.main(Unknown Source)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions