Skip to content

Compiler crash: "failure to construct path" #3917

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
allanrenucci opened this issue Jan 25, 2018 · 2 comments
Closed

Compiler crash: "failure to construct path" #3917

allanrenucci opened this issue Jan 25, 2018 · 2 comments

Comments

@allanrenucci
Copy link
Contributor

allanrenucci commented Jan 25, 2018

class Hello {
  var verbose = false
}

object Main extends Hello {
  def test = {
    verbose = true
  }
}
dotc tests/allan/Test.scala
exception while typing Hello.this of class class dotty.tools.dotc.ast.Trees$This # 227
exception while typing Hello.this.verbose_= of class class dotty.tools.dotc.ast.Trees$Select # 228
exception while typing Hello.this.verbose_=(true) of class class dotty.tools.dotc.ast.Trees$Apply # 229
exception while typing {
  Hello.this.verbose_=(true)
} of class class dotty.tools.dotc.ast.Trees$Block # 230
exception while typing def test: Unit = 
  {
    Hello.this.verbose_=(true)
  } of class class dotty.tools.dotc.ast.Trees$DefDef # 231
exception while typing @scala.annotation.internal.SourceFile("tests/allan/Test.scala") final module 
  class
 Main() extends Hello() { 
  def test: Unit = 
    {
      Hello.this.verbose_=(true)
    }
} of class class dotty.tools.dotc.ast.Trees$TypeDef # 233
exception while typing package <empty> {
  @scala.annotation.internal.SourceFile("tests/allan/Test.scala") class Hello()
     extends
   Object() { 
    <accessor> def verbose: Boolean = false
    <accessor> def verbose_=(x$1: Boolean): Unit = ()
  }
  final lazy module val Main: Main = new Main()
  @scala.annotation.internal.SourceFile("tests/allan/Test.scala") final module 
    class
   Main() extends Hello() { 
    def test: Unit = 
      {
        Hello.this.verbose_=(true)
      }
  }
} of class class dotty.tools.dotc.ast.Trees$PackageDef # 234
exception occurred while compiling tests/allan/Test.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: failure to construct path from method test/object Main/package <empty>/package <root> to `this` of class Hello;
object Main does not have an outer accessor
	at dotty.DottyPredef$.assertFail(DottyPredef.scala:36)
	at dotty.tools.dotc.transform.ExplicitOuter$OuterOps$.loop$1(ExplicitOuter.scala:386)
	at dotty.tools.dotc.transform.ExplicitOuter$OuterOps$.path$extension(ExplicitOuter.scala:392)
	at dotty.tools.dotc.transform.Erasure$Typer.typedThis(Erasure.scala:454)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1721)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1770)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:94)
	at dotty.tools.dotc.typer.Typer.op1$2(Typer.scala:1787)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1783)
	at dotty.tools.dotc.transform.Erasure$Typer.typedSelect(Erasure.scala:442)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1701)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1769)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:94)
	at dotty.tools.dotc.typer.Typer.op1$2(Typer.scala:1787)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1783)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1844)
	at dotty.tools.dotc.transform.Erasure$Typer.typedApply(Erasure.scala:492)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1720)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1770)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:94)
	at dotty.tools.dotc.typer.Typer.op1$2(Typer.scala:1787)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1783)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1844)
	at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:646)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1727)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1770)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:94)
	at dotty.tools.dotc.typer.Typer.op1$2(Typer.scala:1787)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1783)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1844)
	at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:1381)
	at dotty.tools.dotc.transform.Erasure$Typer.typedDefDef(Erasure.scala:577)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1708)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1769)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:94)
	at dotty.tools.dotc.typer.Typer.op1$2(Typer.scala:1787)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1783)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1809)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1832)
	at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:672)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:1422)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1711)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1769)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:94)
	at dotty.tools.dotc.typer.Typer.op1$2(Typer.scala:1787)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1783)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1809)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1832)
	at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:672)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:1593)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1751)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1770)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:94)
	at dotty.tools.dotc.typer.Typer.op1$2(Typer.scala:1787)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1783)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1844)
	at dotty.tools.dotc.transform.Erasure.run(Erasure.scala:99)
	at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:293)
	at scala.collection.immutable.List.map(List.scala:283)
	at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:295)
	at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:123)
	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:136)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:141)
	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:143)
	at dotty.tools.dotc.Run.compileSources(Run.scala:94)
	at dotty.tools.dotc.Run.compile(Run.scala:78)
	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)
@smarter
Copy link
Member

smarter commented Jan 25, 2018

This crashes earlier with -Ycheck:all:

checking try/i3917.scala after phase MegaPhase{phantomArgLift, vcInlineMethods, seqLiterals, intercepted, getters, elimByName, elimOuterSelect, augmentScala2Traits, resolveSuper, simplify, primitiveForwarders, functionXXLForwarders, arrayConstructors}
exception while typing Hello.this of class class dotty.tools.dotc.ast.Trees$This # 198
*** error while checking try/i3917.scala after phase arrayConstructors ***
exception occurred while compiling try/i3917.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: error while typing Hello.this, method test is not contained in class Hello
        at scala.Predef$.assert(Predef.scala:219)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedThis(TreeChecker.scala:352)
...

Workaround: write this.verbose = true or Main.verbose = true.

@smarter
Copy link
Member

smarter commented Jan 25, 2018

In the mini-phase Getters, Hello.verbose = true gets translated to Main.this.verbose = true. I think the problem is caused by the implementation of tpd#becomes: https://github.com/lampepfl/dotty/blob/bfb65c682375652ac98ce55c645f2a9bcf86ba78/compiler/src/dotty/tools/dotc/ast/tpd.scala#L824-L833 Notice that it is constructing a tree from a symbol instead of a denotation, so the prefix may not be correct.

allanrenucci added a commit to dotty-staging/dotty that referenced this issue Jan 26, 2018
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Jan 26, 2018
allanrenucci added a commit that referenced this issue Jan 30, 2018
odersky pushed a commit to dotty-staging/dotty that referenced this issue Jan 31, 2018
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