Skip to content

Exception in thread "main" java.lang.AssertionError: cannot merge Constraint(...) #4272

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
michelou opened this issue Apr 8, 2018 · 2 comments · Fixed by #4276
Closed

Exception in thread "main" java.lang.AssertionError: cannot merge Constraint(...) #4272

michelou opened this issue Apr 8, 2018 · 2 comments · Fixed by #4276
Assignees

Comments

@michelou
Copy link
Contributor

michelou commented Apr 8, 2018

Scala source code:

object Main {

  final case class C(m: Map[String, Boolean])

  def main(args: Array[String]): Unit = {
    // println(C(Map("a" -> true)))  // C(Map(a -> true))
    println(C(Map('a' -> true)))  // Scala: one error found, Dotty: runtime exception
  }

}

Scala compiler output (MS Windows 7 SP1, Java SDK 1.8.0_161):

> scalac -version
Scala compiler version 2.12.5 -- Copyright 2002-2018, LAMP/EPFL and Lightbend, Inc.

> scalac -d c:\temp\classes src\main\scala\Main.scala
src\main\scala\Main.scala:7: error: type mismatch;
 found   : (Char, Boolean)
 required: (String, Boolean)
    println(C(Map('a' -> true)))  // Scala: one error found, Dotty: runtime exception
                      ^
one error found

Dotty compiler output (MS Windows 7 SP1, Java SDK 1.8.0_161):

> dotc -version
Dotty compiler version 0.7.0-RC1 -- Copyright 2002-2018, LAMP/EPFL

> dotc -d c:\temp\classes src\main\scala\Main.scala
exception occurred while typechecking src\main\scala\Main.scala
exception occurred while compiling src\main\scala\Main.scala
Exception in thread "main" java.lang.AssertionError: cannot merge Constraint(
 uninstVars = A;
 constrained types = [A, B](elems: (A, B)*): Map[A, B]
 bounds =
     A >: Char
     B := Boolean
 ordering =
) with Constraint(
 uninstVars = A, Boolean;
 constrained types = [A, B](elems: (A, B)*): Map[A, B]
 bounds =
     A >: String <: String
     B <: Boolean
 ordering =
)
        at dotty.tools.dotc.core.OrderingConstraint.mergeError$1(OrderingConstraint.scala:538)
        at dotty.tools.dotc.core.OrderingConstraint.mergeEntries$1(OrderingConstraint.scala:535)
        at dotty.tools.dotc.core.OrderingConstraint.$amp$$anonfun$1(OrderingConstraint.scala:542)
        at dotty.tools.dotc.core.OrderingConstraint.mergeArrays$1$$anonfun$1(OrderingConstraint.scala:509)
        at scala.compat.java8.JFunction1$mcVI$sp.apply(JFunction1$mcVI$sp.java:12)
        at scala.collection.immutable.Range.foreach(Range.scala:156)
        at dotty.tools.dotc.core.OrderingConstraint.mergeArrays$2(OrderingConstraint.scala:509)
        at dotty.tools.dotc.core.OrderingConstraint.merge$2$$anonfun$1(OrderingConstraint.scala:514)
        at scala.compat.java8.JProcedure2.apply(JProcedure2.java:18)
        at scala.compat.java8.JProcedure2.apply(JProcedure2.java:10)
        at dotty.tools.dotc.util.SimpleIdentityMap$Map1.foreachBinding(SimpleMap.scala:56)
        at dotty.tools.dotc.core.OrderingConstraint.merge$1(OrderingConstraint.scala:514)
        at dotty.tools.dotc.core.OrderingConstraint.$amp(OrderingConstraint.scala:542)
        at dotty.tools.dotc.core.TyperState.commit(TyperState.scala:158)
        at dotty.tools.dotc.typer.Applications.fail$1(Applications.scala:732)
        at dotty.tools.dotc.typer.Applications.realApply$6$$anonfun$5$$anonfun$2(Applications.scala:738)
        at scala.Option.getOrElse(Option.scala:121)
        at dotty.tools.dotc.typer.Applications.realApply$7$$anonfun$6(Applications.scala:739)
        at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:1882)
        at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:674)
        at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:774)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1740)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1791)
        at dotty.tools.dotc.typer.ProtoTypes$FunProto.$anonfun$1(ProtoTypes.scala:244)
        at dotty.tools.dotc.typer.ProtoTypes$FunProto.cacheTypedArg(ProtoTypes.scala:222)
        at dotty.tools.dotc.typer.ProtoTypes$FunProto.typedArg(ProtoTypes.scala:244)
        at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:645)
        at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:645)
        at dotty.tools.dotc.typer.Applications$Application.addTyped$1(Applications.scala:414)
        at dotty.tools.dotc.typer.Applications$Application.matchArgs(Applications.scala:454)
        at dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:235)
        at dotty.tools.dotc.typer.Applications$TypedApply.<init>(Applications.scala:546)
        at dotty.tools.dotc.typer.Applications$ApplyToUntyped.<init>(Applications.scala:644)
        at dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:704)
        at dotty.tools.dotc.typer.Applications.realApply$4$$anonfun$3(Applications.scala:729)
        at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:1880)
        at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:674)
        at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:774)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1740)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1791)
        at dotty.tools.dotc.typer.Typer.op1$2(Typer.scala:1807)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1803)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1872)
        at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:665)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1747)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1791)
        at dotty.tools.dotc.typer.Typer.op1$2(Typer.scala:1807)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1803)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1872)
        at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:1387)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1728)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1790)
        at dotty.tools.dotc.typer.Typer.op1$2(Typer.scala:1807)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1803)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1831)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1860)
        at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:1432)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1731)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1790)
        at dotty.tools.dotc.typer.Typer.op1$2(Typer.scala:1807)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1803)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1831)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1860)
        at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:1600)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1771)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1791)
        at dotty.tools.dotc.typer.Typer.op1$2(Typer.scala:1807)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1803)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1872)
        at dotty.tools.dotc.typer.FrontEnd.typeCheck$$anonfun$1(FrontEnd.scala:66)
        at scala.compat.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
        at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:34)
        at dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:70)
        at dotty.tools.dotc.typer.FrontEnd.runOn$$anonfun$3(FrontEnd.scala:95)
        at scala.compat.java8.JProcedure1.apply(JProcedure1.java:18)
        at scala.compat.java8.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.immutable.List.foreach(List.scala:389)
        at dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:95)
        at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:168)
        at scala.compat.java8.JProcedure1.apply(JProcedure1.java:18)
        at scala.compat.java8.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:32)
        at scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:29)
        at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:191)
        at dotty.tools.dotc.Run.runPhases$5(Run.scala:183)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:191)
        at scala.compat.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:88)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:198)
        at dotty.tools.dotc.Run.compileSources(Run.scala:136)
        at dotty.tools.dotc.Run.compile(Run.scala:120)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:29)
        at dotty.tools.dotc.Driver.process(Driver.scala:127)
        at dotty.tools.dotc.Driver.process(Driver.scala:96)
        at dotty.tools.dotc.Driver.process(Driver.scala:108)
        at dotty.tools.dotc.Driver.main(Driver.scala:135)
        at dotty.tools.dotc.Main.main(Main.scala)
@Blaisorblade Blaisorblade self-assigned this Apr 8, 2018
Blaisorblade added a commit to dotty-staging/dotty that referenced this issue Apr 8, 2018
Debugging revealed that in the failing testcase `e2: TypeBounds` while `e1:
TypeRef`, and it's not clear why it should be otherwise.

Other fixes are possible, this one is easy to maintain but will repeat a few
checks.
Blaisorblade added a commit to dotty-staging/dotty that referenced this issue Apr 9, 2018
Debugging revealed that in the failing testcase `e2: TypeBounds` while `e1:
TypeRef`, and it's not clear why it should be otherwise.

Other fixes are possible, this one is easy to maintain but will repeat a few
checks.
Blaisorblade added a commit to dotty-staging/dotty that referenced this issue Apr 9, 2018
Debugging revealed that in the failing testcase `e2: TypeBounds` while `e1:
TypeRef`, and it's not clear why it should be otherwise.

Other fixes are possible, this one is easy to maintain but will repeat a few
checks.
@Blaisorblade
Copy link
Contributor

Thanks for the report! My WIP fix in #4276 gets the desired error:

-- [E007] Type Mismatch Error: tests/neg/i4272.scala:3:16 ----------------------
3 |  println(C(Map('a' -> true)))  // error
  |                ^^^^^^^^^^^
  |                found:    (Char, Boolean)
  |                required: (String, Boolean)
  |
one error found

@Blaisorblade
Copy link
Contributor

Blaisorblade commented Apr 9, 2018

Minimized further to:

object Main {
  def f(m: Map[String, Boolean]) = {}
  println(f(Map('a' -> true)))  // error, no crash
  println(this.f(Map('a' -> true)))  // error and crash
}

EDIT: The call to f must have some prefix to trigger this crash — any will do, but a direct call won't.

Blaisorblade added a commit to dotty-staging/dotty that referenced this issue Apr 9, 2018
Blaisorblade added a commit to dotty-staging/dotty that referenced this issue Apr 9, 2018
Debugging revealed that in the failing testcase `e2: TypeBounds` while `e1:
TypeRef`, and it's not clear why it should be otherwise.
Blaisorblade added a commit that referenced this issue Apr 9, 2018
Fix #4272: make OrderingConstraint.&.mergeEntries symmetric
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.

2 participants