Skip to content

Commit 4fc36bc

Browse files
Backport "Identify structural trees on Match Type qualifiers" to LTS (#20744)
Backports #18765 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents 7ee6c41 + 0771abd commit 4fc36bc

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Ifce[BT <: Boolean]:
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+
7+
class Test:
8+
def t1: Unit =
9+
val full1 = new Ifce[true]().cast
10+
val v1 = full1.v1 // error
11+
// ^^^^^
12+
// Found: (full1 : Ifce[(true : Boolean)]#RT)
13+
// 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)