Skip to content

Commit ff90012

Browse files
committed
Identify structural trees on Match Type qualifiers
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.
1 parent 38559d7 commit ff90012

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,8 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
992992
def hasRefinement(qualtpe: Type): Boolean = qualtpe.dealias match
993993
case defn.PolyFunctionOf(_) =>
994994
false
995+
case tp: MatchType =>
996+
hasRefinement(tp.tryNormalize)
995997
case RefinedType(parent, rname, rinfo) =>
996998
rname == tree.name || hasRefinement(parent)
997999
case tp: TypeProxy =>

tests/neg/i17192.5.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Ifce[BT <: Boolean]:
2+
type RT = BT match
3+
case true => this.type { val v1: Int }
4+
def cast: RT = this.asInstanceOf[RT]
5+
6+
class Test:
7+
def t1: Unit =
8+
val full1 = new Ifce[true]().cast
9+
val v1 = full1.v1 // error
10+
// ^^^^^
11+
// Found: (full1 : Ifce[(true : Boolean)]#RT)
12+
// Required: Selectable | Dynamic

tests/pos/i17192.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Ifce[BT <: Boolean] extends Selectable:
2+
type RT = BT match
3+
case true => this.type { val v1: Int }
4+
case false => this.type
5+
def cast : RT = this.asInstanceOf[RT]
6+
def selectDynamic(key: String): Any = ???
7+
8+
class Test:
9+
def t1: Unit =
10+
val full = (new Ifce[true]).cast
11+
val v1 = full.v1

0 commit comments

Comments
 (0)