Skip to content

Commit

Permalink
Identify structural trees on Match Type qualifiers
Browse files Browse the repository at this point in the history
Without this change, selecting `v1` on a type `Ifce[(true :
Boolean)]#RT` which widens to a MatchType wouldn't be identified as a
structural tree, which later breaks Erasure.
  • Loading branch information
dwijnand committed Oct 26, 2023
1 parent 38559d7 commit ff90012
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,8 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
def hasRefinement(qualtpe: Type): Boolean = qualtpe.dealias match
case defn.PolyFunctionOf(_) =>
false
case tp: MatchType =>
hasRefinement(tp.tryNormalize)
case RefinedType(parent, rname, rinfo) =>
rname == tree.name || hasRefinement(parent)
case tp: TypeProxy =>
Expand Down
12 changes: 12 additions & 0 deletions tests/neg/i17192.5.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Ifce[BT <: Boolean]:
type RT = BT match
case true => this.type { val v1: Int }
def cast: RT = this.asInstanceOf[RT]

class Test:
def t1: Unit =
val full1 = new Ifce[true]().cast
val v1 = full1.v1 // error
// ^^^^^
// Found: (full1 : Ifce[(true : Boolean)]#RT)
// Required: Selectable | Dynamic
11 changes: 11 additions & 0 deletions tests/pos/i17192.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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 = ???

class Test:
def t1: Unit =
val full = (new Ifce[true]).cast
val v1 = full.v1

0 comments on commit ff90012

Please sign in to comment.