Skip to content

Commit 0ce0955

Browse files
dwijnandWojciechMazur
authored andcommitted
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. [Cherry-picked ff90012]
1 parent 5f83eb3 commit 0ce0955

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
@@ -949,6 +949,8 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
949949
def hasRefinement(qualtpe: Type): Boolean = qualtpe.dealias match
950950
case defn.PolyOrErasedFunctionOf(_) =>
951951
false
952+
case tp: MatchType =>
953+
hasRefinement(tp.tryNormalize)
952954
case RefinedType(parent, rname, rinfo) =>
953955
rname == tree.name || hasRefinement(parent)
954956
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)