Skip to content

Commit c0eae68

Browse files
authored
Identify structural trees on Match Type qualifiers (#18765)
2 parents c2313d2 + cc69d90 commit c0eae68

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

Diff for: compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

+2
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 =>

Diff for: tests/neg/i17192.5.scala

+13
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

Diff for: tests/pos/i17192.scala

+11
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)