Skip to content

Crash in ExplicitOuter when calling new on a type alias to an inner class #1865

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
helloqirun opened this issue Jan 1, 2017 · 5 comments
Closed

Comments

@helloqirun
Copy link

scalac compiles but dotc crashes.

$ cat abc.scala

class AbsCell {
  type T = Node
  val value: T = value
  def set(x: T): Unit = {}
  class Node
}
object init {
  def main = {
    val cell = new AbsCell { val init = new Node }
    cell set (new cell.T)
  }
}

$ dotc abc.scala

exception while typing AbsCell.this of class class dotty.tools.dotc.ast.Trees$This # 404
exception while typing new AbsCell.this.Node() of class class dotty.tools.dotc.ast.Trees$Apply # 284
exception while typing cell.set(new AbsCell.this.Node()) of class class dotty.tools.dotc.ast.Trees$Apply # 286
exception while typing {
  val cell: AbsCell =
    {
      final class $anon() extends AbsCell() {
        <accessor> def init: Node = new Node()
      }
      new AbsCell{...}(): AbsCell
    }
  cell.set(new AbsCell.this.Node())
} of class class dotty.tools.dotc.ast.Trees$Block # 306
exception while typing def main: Unit =
  {
    val cell: AbsCell =
      {
        final class $anon() extends AbsCell() {
          <accessor> def init: Node = new Node()
        }
        new AbsCell{...}(): AbsCell
      }
    cell.set(new AbsCell.this.Node())
  } of class class dotty.tools.dotc.ast.Trees$DefDef # 307
exception while typing @scala.annotation.internal.SourceFile("abc.scala") final module class init$()
   extends
 Object() {
  def main: Unit =
    {
      val cell: AbsCell =
        {
          final class $anon() extends AbsCell() {
            <accessor> def init: Node = new Node()
          }
          new AbsCell{...}(): AbsCell
        }
      cell.set(new AbsCell.this.Node())
    }
} of class class dotty.tools.dotc.ast.Trees$TypeDef # 309
exception while typing package <empty> {
  @scala.annotation.internal.SourceFile("abc.scala") class AbsCell() extends
    Object
  () {
    type TAbsCell.this.Node
    <accessor> def value: AbsCell.this.T = this.value
    def set(x: AbsCell.this.T): Unit =
      {
        ()
      }
    class Node() extends Object() {
      private <accessor> def $outer: AbsCell
      final def AbsCell$Node$$$outer: AbsCell = Node.this.$outer
    }
  }
  final lazy module val init: init$ = new init$()
  @scala.annotation.internal.SourceFile("abc.scala") final module class init$()
     extends
   Object() {
    def main: Unit =
      {
        val cell: AbsCell =
          {
            final class $anon() extends AbsCell() {
              <accessor> def init: Node = new Node()
            }
            new AbsCell{...}(): AbsCell
          }
        cell.set(new AbsCell.this.Node())
      }
  }
} of class class dotty.tools.dotc.ast.Trees$PackageDef # 310

exception occurred while compiling abc.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: failure to construct path from method main/object init/package <empty>/package <root> to `this` of class AbsCell;
object init does not have an outer accessor
	at scala.Predef$.assert(Predef.scala:165)
	at dotty.tools.dotc.transform.ExplicitOuter$OuterOps$.loop$1(ExplicitOuter.scala:367)
	at dotty.tools.dotc.transform.ExplicitOuter$OuterOps$.path$extension(ExplicitOuter.scala:373)
	at dotty.tools.dotc.transform.Erasure$Typer.typedThis(Erasure.scala:420)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1490)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1535)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:96)
	at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1553)
	at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1551)
	at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:136)
	at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1551)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1607)
	at dotty.tools.dotc.transform.Erasure$Typer$$anonfun$4.apply(Erasure.scala:471)
	at dotty.tools.dotc.transform.Erasure$Typer$$anonfun$4.apply(Erasure.scala:471)
	at dotty.tools.dotc.core.Decorators$ListDecorator$.zipWithConserve$extension(Decorators.scala:98)
	at dotty.tools.dotc.transform.Erasure$Typer.typedApply(Erasure.scala:471)
<...>
@smarter
Copy link
Member

smarter commented Jan 1, 2017

This is similar to #1755

@smarter
Copy link
Member

smarter commented Jan 1, 2017

Here's a minimization that still triggers the crash (I didn't know you could call new on a type alias!);

class AbsCell {
  type T = Node
  class Node
}

object Test {
  def test: Unit = {
    val cell = new AbsCell
    new cell.T
  }
}

@smarter smarter changed the title crash on compilable code: failure to construct path from method ... Crash in ExplicitOuter when calling new on a type alias to an inner class Jan 1, 2017
@odersky
Copy link
Contributor

odersky commented Jan 2, 2017

@this one, as well as #1866 and #1867 exercise various aspects of structural types. The status of this feature is currently unclear, we are not yet sure whether we will fully implement it or forbid it. So for now it's better to hold off wth testing this.

@smarter
Copy link
Member

smarter commented Jan 2, 2017

@odersky I don't understand how this one has anything to do with structural types? Also #1867 is something we already support, {} is syntactic sugar for AnyRef {} which works fine.

@odersky
Copy link
Contributor

odersky commented Jan 3, 2017

@smarter The original code contained a structural type but your minimization does not. So, yes, it's something else.

@odersky odersky self-assigned this Jan 3, 2017
@odersky odersky closed this as completed in c40302c Jan 5, 2017
odersky added a commit that referenced this issue Jan 5, 2017
Fix #1865: Compute outer path at right phase
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

4 participants