Skip to content

Compiler crash when compiling a bare Map construction with unknown types #2979

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
vlthr opened this issue Aug 15, 2017 · 1 comment
Closed

Comments

@vlthr
Copy link
Contributor

vlthr commented Aug 15, 2017

Compiling the following file results in an AssertionError using the latest nightly build (also tested in 0.2.0-RC1 and 0.1.2-RC1):

object Main {
  Map(
    "a" -> Unknown(),
    "b" -> Unknown()
  )
}

The stack trace is as follows:

exception occurred while compiling /home/von/bb/dotty-test/src/main/scala/main.scala
java.lang.AssertionError: assertion failed
        at scala.Predef$.assert(Predef.scala:156)
        at dotty.tools.dotc.core.ConstraintHandling.approximation(ConstraintHandling.scala:232)
        at dotty.tools.dotc.core.ConstraintHandling.instanceType(ConstraintHandling.scala:266)
        at dotty.tools.dotc.core.Types$TypeVar.instantiate(Types.scala:3215)
        at dotty.tools.dotc.typer.Inferencing$.op$78$$anonfun$4(Inferencing.scala:264)
        at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
        at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48)
        at dotty.tools.dotc.typer.Inferencing$.op$78(Inferencing.scala:265)
        at dotty.tools.dotc.typer.Inferencing$.interpolate$2(Inferencing.scala:221)
        at dotty.tools.dotc.typer.Inferencing$.interpolateUndetVars(Inferencing.scala:267)
        at dotty.tools.dotc.typer.Typer.op$125(Typer.scala:1830)
        at dotty.tools.dotc.typer.Typer.op$124(Typer.scala:1829)
        at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:1828)
        at dotty.tools.dotc.typer.Typer.op$122(Typer.scala:1680)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1678)
        at dotty.tools.dotc.typer.Typer.traverse$4(Typer.scala:1702)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1725)
        at dotty.tools.dotc.typer.Typer.op$120(Typer.scala:1508)
        at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:1495)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1648)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1665)
        at dotty.tools.dotc.typer.Typer.op$122(Typer.scala:1680)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1678)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1737)
        at dotty.tools.dotc.typer.FrontEnd.typeCheck$$anonfun$1(FrontEnd.scala:64)
        at scala.compat.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
        at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:32)
        at dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:68)
        at dotty.tools.dotc.typer.FrontEnd.runOn$$anonfun$5(FrontEnd.scala:93)
        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:392)
        at dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:93)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1$$anonfun$1(Run.scala:82)
        at scala.compat.java8.JProcedure1.apply(JProcedure1.java:18)
        at scala.compat.java8.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
        at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:186)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:90)
        at scala.compat.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
        at dotty.tools.dotc.util.Stats$.monitorHeartBeat(Stats.scala:76)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:95)
        at dotty.tools.dotc.Run.compileSources(Run.scala:64)
        at dotty.tools.dotc.Run.compile(Run.scala:48)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:26)
        at dotty.tools.dotc.Driver.process(Driver.scala:124)
...

A minimal reproduction is also available in the assertion-error branch of vlthr/dotty-test.

The error disappears when:

  • The Map constructor call is placed on the right hand side of a val or def.
  • A case class or object (with an associated apply method) named Unknown is defined.

Creating just an object Unknown without an apply method results in a compile error: object Unknown does not take parameters but that is still followed by the same AssertionError.

@biboudis
Copy link
Contributor

Reproducing! Thanks for reporting!

@biboudis biboudis changed the title AssertionError in ConstraintHandling.scala relating to unknown types Compiler crash when compiling a bare Map construction with unknown types Aug 15, 2017
odersky added a commit to dotty-staging/dotty that referenced this issue Jan 14, 2018
During interpolation a type parameter might become instantiated. This is
now handled correctly.
odersky added a commit that referenced this issue Jan 15, 2018
Fix #2979: Allow for instantiated params when approximating
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants