Skip to content

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

Closed
@helloqirun

Description

@helloqirun

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)
<...>

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions