Skip to content

Commit 1c900a3

Browse files
committed
Recurse into refined type when exposing members
1 parent 9e45ad1 commit 1c900a3

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,12 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
537537
tp.refinedName,
538538
tpb.derivedTypeBounds(follow(lo, false), follow(hi, true))
539539
)
540-
case tp => tp
540+
case _ =>
541+
tp.derivedRefinedType(
542+
expose(tp.parent),
543+
tp.refinedName,
544+
tp.refinedInfo
545+
)
541546
}
542547
case _ => tp
543548
}

tests/patmat/i2253.check

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
27: Pattern Match Exhaustivity: HasIntXIntM, HasIntXStringM
2+
28: Pattern Match Exhaustivity: HasIntXIntM
3+
29: Pattern Match Exhaustivity: HasIntXIntM

tests/patmat/i2253.scala

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,30 @@
11
sealed trait S
2-
object O extends S
2+
3+
object BodylessObject extends S
4+
5+
object HasIntM extends S {
6+
type M = Int
7+
}
8+
9+
object HasStringXStringM extends S {
10+
type M = String
11+
val x: String = ""
12+
}
13+
14+
object HasIntXStringM extends S {
15+
type M = String
16+
val x: Int = 0
17+
}
18+
19+
object HasIntXIntM extends S {
20+
type M = Int
21+
val x: Int = 0
22+
}
23+
324
trait T
425

526
class Test {
6-
def m(s: S { val x: Int }) = s match { case _: T => ; }
7-
}
27+
def onlyIntX(s: S { val x: Int }) = s match { case _: T => ; }
28+
def exposeAlias1[I <: Int](s: S { type M = I; val x: Int }) = s match { case _: T => ; }
29+
def exposeAlias2[I <: Int](s: S { val x: Int; type M = I }) = s match { case _: T => ; }
30+
}

0 commit comments

Comments
 (0)