diff --git a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala index ac7fec4b02df..23dcfe392c27 100644 --- a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala +++ b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala @@ -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 => diff --git a/tests/neg/i17192.5.scala b/tests/neg/i17192.5.scala new file mode 100644 index 000000000000..2837af36b573 --- /dev/null +++ b/tests/neg/i17192.5.scala @@ -0,0 +1,12 @@ +class Ifce[BT <: Boolean]: + type RT = BT match + case true => this.type { val v1: Int } + 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 diff --git a/tests/pos/i17192.scala b/tests/pos/i17192.scala new file mode 100644 index 000000000000..129da358b3ba --- /dev/null +++ b/tests/pos/i17192.scala @@ -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