Skip to content

Commit 34336af

Browse files
committed
Fix isStructuralTermSelectOrApply
When looking at AppliedTypes, we want to go to the supertype (which is the dealiased type or upper bound), not the underlying type (which is the type constructor). This is the second bug in a week caused by a confusion of unerlying and supertype for AppliedTypes. We should do an audit of the codebase to see whether there are more cases like this. Fixes #15448
1 parent 836ed97 commit 34336af

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
869869
case RefinedType(parent, rname, rinfo) =>
870870
rname == tree.name || hasRefinement(parent)
871871
case tp: TypeProxy =>
872-
hasRefinement(tp.underlying)
872+
hasRefinement(tp.superType)
873873
case tp: AndType =>
874874
hasRefinement(tp.tp1) || hasRefinement(tp.tp2)
875875
case tp: OrType =>

tests/neg/i15448.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
object Minimized:
2+
type Pointer[S <: Int] <: S
3+
4+
type Break = Int {
5+
def boom: Unit
6+
}
7+
8+
def test = {
9+
val ptrBreak: Pointer[Break] = ???
10+
ptrBreak.boom // error Required: Selectable, was boom crashes the compiler
11+
}

tests/pos/i15448.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
object SelectableBreaks1 {
2+
object opaques {
3+
opaque type Pointer[S] <: S = S
4+
object Pointer {
5+
implicit class PointerSelectable[S](private val f: Pointer[S]) extends Selectable {
6+
def selectDynamic(name: String): Any = ???
7+
def applyDynamic(name: String)(): Any = ???
8+
}
9+
}
10+
}
11+
import opaques.*
12+
13+
type Break = AnyRef {
14+
def boom(): Nothing
15+
}
16+
17+
def makeBreak(): Pointer[Break] = ???
18+
19+
makeBreak().boom()
20+
}
21+

0 commit comments

Comments
 (0)