Skip to content

AssertionError when typechecking a match with variance #9533

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

Closed
adamw opened this issue Aug 11, 2020 · 1 comment · Fixed by #10109
Closed

AssertionError when typechecking a match with variance #9533

adamw opened this issue Aug 11, 2020 · 1 comment · Fixed by #10109

Comments

@adamw
Copy link
Contributor

adamw commented Aug 11, 2020

Minimized code

object Test {
  sealed trait Base[-X]
  case class Child[X]() extends Base[X]

  def apply[A, B](r: Base[A with B]): Unit = {
    r match {
      case Child() => ()
    }
  }
}

This is simplified version of code from sttp. Using dotty 0.26.0-RC1.

Output

java.lang.AssertionError: assertion failed while compiling /Users/adamw/projects/sttp/core/src/main/scala/sttp/client/monad/Test.scala
[error] ## Exception when compiling 45 sources to /Users/adamw/projects/sttp/core/target/jvm-0.26/classes
[error] java.lang.AssertionError: assertion failed
[error] scala.Predef$.assert(Predef.scala:267)
[error] scala.Predef$Ensuring$.ensuring$extension(Predef.scala:362)
[error] dotty.tools.dotc.core.ProperGadtConstraint.fullBounds(GadtConstraint.scala:176)
[error] dotty.tools.dotc.typer.Typer$$anon$1.transform(Typer.scala:1395)
[error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$2(Trees.scala:1371)
[error] scala.collection.immutable.List.mapConserve(List.scala:472)
[error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1371)
[error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1274)
[error] dotty.tools.dotc.typer.Typer$$anon$1.transform(Typer.scala:1388)
[error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1334)
[error] dotty.tools.dotc.typer.Typer$$anon$1.transform(Typer.scala:1388)
[error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1280)
[error] dotty.tools.dotc.typer.Typer$$anon$1.transform(Typer.scala:1388)
[error] dotty.tools.dotc.typer.Typer.caseRest$1(Typer.scala:1426)
[error] dotty.tools.dotc.typer.Typer.typedCase(Typer.scala:1437)
[error] dotty.tools.dotc.typer.Typer.typedCases$$anonfun$1(Typer.scala:1374)
[error] dotty.tools.dotc.core.Decorators$ListDecorator$.loop$1(Decorators.scala:69)
[error] dotty.tools.dotc.core.Decorators$ListDecorator$.mapconserve$extension(Decorators.scala:85)
[error] dotty.tools.dotc.typer.Typer.typedCases(Typer.scala:1376)
[error] dotty.tools.dotc.typer.Typer.$anonfun$17(Typer.scala:1366)
[error] dotty.tools.dotc.typer.Applications.harmonic(Applications.scala:2072)
[error] dotty.tools.dotc.typer.Applications.harmonic$(Applications.scala:233)
[error] dotty.tools.dotc.typer.Typer.harmonic(Typer.scala:91)
[error] dotty.tools.dotc.typer.Typer.typedMatchFinish(Typer.scala:1366)
[error] dotty.tools.dotc.typer.Typer.typedMatch(Typer.scala:1331)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2436)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2484)
[error] dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2553)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2554)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2557)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2671)
[error] dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:871)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2431)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2484)
[error] dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2553)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2554)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2557)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2671)
[error] dotty.tools.dotc.typer.Typer.$anonfun$32(Typer.scala:1946)
[error] dotty.tools.dotc.typer.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:217)
[error] dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:1946)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2400)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2483)
[error] dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2553)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2554)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2557)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2579)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2627)
[error] dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2081)
[error] dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$2(Typer.scala:2411)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2415)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2483)
[error] dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2553)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2554)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2557)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2579)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2627)
[error] dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2207)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2455)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2484)
[error] dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2553)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2554)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2557)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2671)
[error] dotty.tools.dotc.typer.FrontEnd.liftedTree1$1(FrontEnd.scala:78)
[error] dotty.tools.dotc.typer.FrontEnd.typeCheck$$anonfun$1(FrontEnd.scala:83)
[error] dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
[error] dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:42)
[error] dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:84)
[error] dotty.tools.dotc.typer.FrontEnd.runOn$$anonfun$3(FrontEnd.scala:119)
[error] dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.immutable.List.foreach(List.scala:333)
[error] dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:119)
[error] dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:181)
[error] dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
[error] dotty.tools.dotc.Run.runPhases$5(Run.scala:191)
[error] dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:199)
[error] dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
[error] dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:64)
[error] dotty.tools.dotc.Run.compileUnits(Run.scala:206)
[error] dotty.tools.dotc.Run.compileSources(Run.scala:143)
[error] dotty.tools.dotc.Run.compile(Run.scala:125)
[error] dotty.tools.dotc.Driver.doCompile(Driver.scala:38)
[error] dotty.tools.dotc.Driver.process(Driver.scala:195)
[error] dotty.tools.dotc.Main.process(Main.scala)
[error] xsbt.CachedCompilerImpl.run(CachedCompilerImpl.java:69)

Expectation

Compiled code, no error ;)

@IndiscriminateCoding
Copy link

I'm also hitting this (but with union types instead of with).
Workaround is matching on a case class type w/ existentials and then asInstanceOf it to a (hopefully proper) type - which is ugly and easy to get wrong.
Any chances it would be fixed soon?

liufengyun added a commit to dotty-staging/dotty that referenced this issue Oct 28, 2020
liufengyun added a commit that referenced this issue Oct 30, 2020
Fix #9533: handle nested TypeParamRef in bounds
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants