Skip to content

Commit 6229b48

Browse files
committed
Handle refinements where the refined type is a class
1 parent 0ddb47a commit 6229b48

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,13 +589,14 @@ object Types {
589589

590590
def goRefined(tp: RefinedType) = {
591591
val pdenot = go(tp.parent)
592+
val pinfo = pdenot.info
592593
val rinfo = tp.refinedInfo
593-
if (name.isTypeName) { // simplified case that runs more efficiently
594+
if (name.isTypeName && !pinfo.isInstanceOf[ClassInfo]) { // simplified case that runs more efficiently
594595
val jointInfo =
595596
if (rinfo.isAlias) rinfo
596-
else if (pdenot.info.isAlias) pdenot.info
597-
else if (ctx.pendingMemberSearches.contains(name)) pdenot.info safe_& rinfo
598-
else pdenot.info recoverable_& rinfo
597+
else if (pinfo.isAlias) pinfo
598+
else if (ctx.pendingMemberSearches.contains(name)) pinfo safe_& rinfo
599+
else pinfo recoverable_& rinfo
599600
pdenot.asSingleDenotation.derivedSingleDenotation(pdenot.symbol, jointInfo)
600601
} else {
601602
pdenot & (

tests/neg/parser-stability-18.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
trait x0 {
2+
class x1 (x1:x0
3+
{
4+
type x1 <: List[x1 <: // error // error

tests/pos/class-refinement.scala

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
object Test {
2+
3+
class C {
4+
5+
class I
6+
7+
}
8+
9+
trait T
10+
11+
val x: C { type I <: T } = ??? // direct refinement of class member
12+
13+
val y: x.I = ???
14+
15+
}
16+
17+
class B {
18+
class C {
19+
type I
20+
}
21+
trait T
22+
23+
type CC <: C
24+
25+
val x: CC { type I <: T } = ???
26+
}
27+
28+
object Test2 extends B {
29+
30+
class CC extends C { class I }
31+
32+
val y: x.I = ??? // indirect refinement of class member
33+
34+
35+
}
36+

0 commit comments

Comments
 (0)