Skip to content

Commit

Permalink
Backport "Identify structural trees on Match Type qualifiers" to LTS (#…
Browse files Browse the repository at this point in the history
…20744)

Backports #18765 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur authored Jun 23, 2024
2 parents 7ee6c41 + 0771abd commit 4fc36bc
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 @@ -949,6 +949,8 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
def hasRefinement(qualtpe: Type): Boolean = qualtpe.dealias match
case defn.PolyOrErasedFunctionOf(_) =>
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 4fc36bc

Please sign in to comment.