Skip to content

Commit

Permalink
Identify structural trees on Match Type qualifiers (#18765)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand authored Oct 27, 2023
2 parents c2313d2 + cc69d90 commit c0eae68
Show file tree
Hide file tree
Showing 3 changed files with 26 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
13 changes: 13 additions & 0 deletions tests/neg/i17192.5.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Ifce[BT <: Boolean]:
type RT = BT match
case true => this.type { val v1: Int }
case false => this.type
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 c0eae68

Please sign in to comment.