Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identify structural trees on Match Type qualifiers #18765

Merged
merged 2 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
12 changes: 12 additions & 0 deletions tests/neg/i17192.5.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Ifce[BT <: Boolean]:
dwijnand marked this conversation as resolved.
Show resolved Hide resolved
type RT = BT match
case true => this.type { val v1: Int }
dwijnand marked this conversation as resolved.
Show resolved Hide resolved
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
Loading