Skip to content

AST owner loss during a type match #17192

Closed
@ftucky

Description

@ftucky

Compiler version

3.2.2, 3.3.0-RC3

Minimized code

class Ifce[BT <: Boolean] extends Selectable:
  type RT = BT match {
    case true  => this.type  { val v1: Int }
    case false => this.type
  }
  def cast : RT = this.asInstanceOf[RT]
  def selectDynamic(key:String) : Any = ???

val full = (new Ifce[true]).cast

println(s"full.v1 = ${full.v1}")

Output

scala java.lang.AssertionError: assertion failed: no owner from / in Playground.full.v1

java.lang.AssertionError: assertion failed: no owner from <span class="ansi-color-yellow"></span> <span class="ansi-color-magenta">&lt;none&gt;</span>/<span class="ansi-color-yellow"></span> <span class="ansi-color-magenta">&lt;none&gt;</span> in Playground.full.v1
	at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
	at dotty.tools.dotc.transform.Erasure$Typer.typedSelect(Erasure.scala:716)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2897)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2990)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:126)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3058)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3062)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3174)
	at dotty.tools.dotc.transform.Erasure$Typer.$anonfun$7(Erasure.scala:844)
	at dotty.tools.dotc.core.Decorators$.zipWithConserve(Decorators.scala:155)
	at dotty.tools.dotc.transform.Erasure$Typer.typedApply(Erasure.scala:844)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2928)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2991)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:126)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3058)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3062)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3174)
	at dotty.tools.dotc.transform.Erasure$Typer.$anonfun$7(Erasure.scala:844)
	at dotty.tools.dotc.core.Decorators$.zipWithConserve(Decorators.scala:155)
	at dotty.tools.dotc.transform.Erasure$Typer.typedApply(Erasure.scala:844)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2928)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2991)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:126)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3058)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3062)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3174)
	at dotty.tools.dotc.typer.Typer.typedValDef(Typer.scala:2326)
	at dotty.tools.dotc.transform.Erasure$Typer.typedValDef(Erasure.scala:901)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2901)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2990)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:126)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3058)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3062)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3084)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3130)
	at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1047)
	at dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:1096)
	at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1100)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2936)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2991)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:126)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3058)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3062)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3174)
	at dotty.tools.dotc.transform.Erasure$Typer.$anonfun$7(Erasure.scala:844)
	at dotty.tools.dotc.core.Decorators$.zipWithConserve(Decorators.scala:155)
	at dotty.tools.dotc.transform.Erasure$Typer.typedApply(Erasure.scala:844)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2928)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2991)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:126)

Observations

The crash is related to the type match. Following code does not crash.

class Ifce[BT <: Boolean] extends Selectable:
  type RT = this.type & {val v1 : Int}
  def cast : RT = this.asInstanceOf[RT]
  def selectDynamic(key:String) : Any = ???

When the type match is defined outside the class, no crash either.

type RT[BT] = BT match {
    case true  => { val v1: Int }
    case false => {}
  }
class Ifce[BT <: Boolean] extends Selectable:
  def cast : this.type & RT[BT] = this.asInstanceOf[this.type & RT[BT]]
  def selectDynamic(key:String) : Any = ???

extending trait Selectable is not involved. Following code does crash.

class Ifce[BT <: Boolean]:
  type RT = BT match {
    case true  => this.type  { val v1: Int }
    case false => this.type
  }
  def cast : RT = this.asInstanceOf[RT]

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions