Skip to content

AssertionError: invalid prefix MethodType ... #16842

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
mateusz-lichota opened this issue Feb 6, 2023 · 3 comments · Fixed by #16853
Closed

AssertionError: invalid prefix MethodType ... #16842

mateusz-lichota opened this issue Feb 6, 2023 · 3 comments · Fixed by #16853

Comments

@mateusz-lichota
Copy link

Compiler version

3.2.2

Minimized code

sealed trait Expr1
sealed trait Literal extends Expr1

case class ArrayLiter(elems: List[Expr1]) extends Literal

sealed trait SemanticType {
  type T // the type with which a literal of this semanticType is represented
}
case object SemanticInt extends SemanticType {
  type T = Int
}

case class SemanticArray[U <: SemanticType](dim: Int) extends SemanticType {
  type T = List[U]
}

sealed trait Expr2[+T]
class Liter[T <: SemanticType](val ty: T, val value: ty.T) extends Expr2[T]

def typecheckArrayLiter(
    a: ArrayLiter
): Liter[SemanticArray[SemanticType]] = {
  val x: List[Expr2[SemanticInt.type]] = List()
  Liter(SemanticArray[SemanticInt.type], x)
}

Output (click arrow to expand)

java.lang.AssertionError: assertion failed: invalid prefix MethodType(List(dim), List(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),class Int)), AppliedType(TypeRef(ThisType(TypeRef(NoPrefix,module class <empty>)),class SemanticArray),List(TermRef(ThisType(TypeRef(NoPrefix,module class <empty>)),object SemanticInt)))) while typechecking src/main/scala/wacc/Main.scala
exception occurred while typechecking src/main/scala/wacc/Main.scala
exception occurred while compiling src/main/scala/wacc/Main.scala
java.lang.AssertionError: assertion failed: invalid prefix MethodType(List(dim), List(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),class Int)), AppliedType(TypeRef(ThisType(TypeRef(NoPrefix,module class <empty>)),class SemanticArray),List(TermRef(ThisType(TypeRef(NoPrefix,module class <empty>)),object SemanticInt)))) while compiling src/main/scala/wacc/Main.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: invalid prefix MethodType(List(dim), List(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),class Int)), AppliedType(TypeRef(ThisType(TypeRef(NoPrefix,module class <empty>)),class SemanticArray),List(TermRef(ThisType(TypeRef(NoPrefix,module class <empty>)),object SemanticInt))))
        at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
        at dotty.tools.dotc.core.Types$NamedType.<init>(Types.scala:2189)
        at dotty.tools.dotc.core.Types$TypeRef.<init>(Types.scala:2804)
        at dotty.tools.dotc.core.Types$CachedTypeRef.<init>(Types.scala:2860)
        at dotty.tools.dotc.core.Uniques$NamedTypeUniques.newType$1(Uniques.scala:45)
        at dotty.tools.dotc.core.Uniques$NamedTypeUniques.enterIfNew(Uniques.scala:46)
        at dotty.tools.dotc.core.Types$TypeRef$.apply(Types.scala:2919)
        at dotty.tools.dotc.core.Types$TypeRef$.apply(Types.scala:2925)
        at dotty.tools.dotc.core.Types$NamedType$.apply(Types.scala:2899)
        at dotty.tools.dotc.core.Types$NamedType.reload$1(Types.scala:2706)
        at dotty.tools.dotc.core.Types$NamedType.withPrefix(Types.scala:2722)
        at dotty.tools.dotc.core.Types$NamedType.derivedSelect(Types.scala:2636)
        at dotty.tools.dotc.core.Substituters$.substParam(Substituters.scala:142)
        at dotty.tools.dotc.core.Types$Type.substParam(Types.scala:1813)
        at dotty.tools.dotc.typer.TypeAssigner.safeSubstParam(TypeAssigner.scala:275)
        at dotty.tools.dotc.typer.TypeAssigner.safeSubstParam$(TypeAssigner.scala:16)
        at dotty.tools.dotc.typer.Typer.safeSubstParam(Typer.scala:121)
        at dotty.tools.dotc.typer.Applications$Application.addTyped$1$$anonfun$1(Applications.scala:579)
        at dotty.tools.dotc.core.Decorators$ListDecorator$.loop$1(Decorators.scala:91)
        at dotty.tools.dotc.core.Decorators$ListDecorator$.mapconserve$extension(Decorators.scala:107)
        at dotty.tools.dotc.typer.Applications$Application.addTyped$1(Applications.scala:579)
        at dotty.tools.dotc.typer.Applications$Application.matchArgs(Applications.scala:640)
        at dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:479)
        at dotty.tools.dotc.typer.Applications$TypedApply.<init>(Applications.scala:766)
        at dotty.tools.dotc.typer.Applications$ApplyToUntyped.<init>(Applications.scala:883)
        at dotty.tools.dotc.typer.Applications.ApplyTo(Applications.scala:1095)
        at dotty.tools.dotc.typer.Applications.ApplyTo$(Applications.scala:346)
        at dotty.tools.dotc.typer.Typer.ApplyTo(Typer.scala:121)
        at dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:941)
        at dotty.tools.dotc.typer.Applications.realApply$1$$anonfun$3(Applications.scala:1021)
        at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:3169)
        at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:1032)
        at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1070)
        at dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:346)
        at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:121)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2895)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2958)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3025)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3029)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3145)
        at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1069)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2903)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2958)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3025)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3029)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3145)
        at dotty.tools.dotc.typer.Typer.$anonfun$51(Typer.scala:2356)
        at dotty.tools.dotc.inlines.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:249)
        at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:2356)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2871)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2957)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3025)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3029)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3051)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3101)
        at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2532)
        at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:2883)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2887)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2957)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3025)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3029)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3051)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3101)
        at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2659)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2928)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2958)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3025)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3029)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3145)
        at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:44)
        at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$adapted$1(TyperPhase.scala:54)
        at scala.Function0.apply$mcV$sp(Function0.scala:42)
        at dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:429)
        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:238)
        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:249)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:257)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:266)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:68)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:266)
        at dotty.tools.dotc.Run.compileSources(Run.scala:190)
        at dotty.tools.dotc.Run.compile(Run.scala:174)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:35)
        at dotty.tools.dotc.Driver.process(Driver.scala:195)
        at dotty.tools.dotc.Driver.process(Driver.scala:163)
        at dotty.tools.dotc.Driver.process(Driver.scala:175)
        at dotty.tools.dotc.Driver.main(Driver.scala:205)
        at dotty.tools.MainGenericCompiler$.run$1(MainGenericCompiler.scala:162)
        at dotty.tools.MainGenericCompiler$.main(MainGenericCompiler.scala:186)
        at dotty.tools.MainGenericCompiler.main(MainGenericCompiler.scala)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at coursier.bootstrap.launcher.a.a(Unknown Source)
        at coursier.bootstrap.launcher.Launcher.main(Unknown Source)
@mateusz-lichota mateusz-lichota added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 6, 2023
@jchyb
Copy link
Contributor

jchyb commented Feb 7, 2023

Hi! Thank you for submitting the issue. Fortunately, this appears to be fixed on main (21729d2) and in 3.3.0-RC2, which means that this will be fixed in the next version of Scala (3.3.0). Instead of a crash we now get errors, all of which appear to be correct:

-- [E007] Type Mismatch Error: main.scala:24:8 ---------------------------------
24 |  Liter(SemanticArray[SemanticInt.type], x)
   |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |        Found:    Int => SemanticArray[SemanticInt.type]
   |        Required: SemanticArray[SemanticType]
   |
   | longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: main.scala:24:41 --------------------------------
24 |  Liter(SemanticArray[SemanticInt.type], x)
   |                                         ^
   |Found:    (x : List[Expr2[SemanticInt.type]])
   |Required: ?1.T
   |
   |where:    ?1 is an unknown value of type (dim: Int): SemanticArray[SemanticInt.type]
   |
   | longer explanation available when compiling with `-explain`

As an extra, here is a version that fixes the above errors (and also compiles on 3.2.2):

sealed trait Expr1
sealed trait Literal extends Expr1

case class ArrayLiter(elems: List[Expr1]) extends Literal

sealed trait SemanticType {
  type T // the type with which a literal of this semanticType is represented
}
case object SemanticInt extends SemanticType {
  type T = Int
}

case class SemanticArray[U <: SemanticType](dim: Int) extends SemanticType {
  type T = List[U]
}

sealed trait Expr2[+T]
class Liter[T <: SemanticType](val ty: T, val value: ty.T) extends Expr2[T]

def typecheckArrayLiter(
    a: ArrayLiter
): Liter[SemanticArray[? <: SemanticType]] = { // bit of a hack here, usually we would just make SemanticArray type parameter covariant, but here we would get an error: "covariant type U occurs in invariant position in type  = List[U] of type T"
  val x: List[SemanticInt.type] = List() // removed Expr2 from type declaration
  Liter(SemanticArray[SemanticInt.type](0), x) // added a missing argument
}

@jchyb jchyb added stat:cannot reproduce and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 7, 2023
@som-snytt
Copy link
Contributor

I would expect "cannot reproduce" to mean the reported symptom can't be reproduced in a lab setting, rather than "can't be reproduced because the bug is already fixed." (I happened to arrive here because "cannot reproduce" is also a challenge.)

@nicolasstucki
Copy link
Contributor

nicolasstucki commented Feb 8, 2023

@som-snytt you are right "cannot reproduce" should be used when we can't be reproduced in a lab setting.

From what I understand, we could reproduce the issue on 3.2.2. Is that right @jchyb?<\del>

It does fail as reported in 3.2.2.

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 8, 2023
nicolasstucki added a commit that referenced this issue Feb 8, 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.

4 participants