Skip to content

Commit 9cd5fc2

Browse files
dwijnandWojciechMazur
authored andcommitted
Fix unreachable warning in deeply nested sealed hierarchy
Without applying we were constructing the type Jacket#Body, instead of Jacket[?]#Body, which lead down to an incorrect isSubSpace calculation and thus an unreachable warning. [Cherry-picked 9460b7d]
1 parent 3cee254 commit 9cd5fc2

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ object TypeOps:
883883
else if symbol.is(Module) then
884884
TermRef(this(tref.prefix), symbol.sourceModule)
885885
else if (prefixTVar != null)
886-
this(tref)
886+
this(tref.applyIfParameterized(tref.typeParams.map(_ => WildcardType)))
887887
else {
888888
prefixTVar = WildcardType // prevent recursive call from assigning it
889889
// e.g. tests/pos/i15029.more.scala, create a TypeVar for `Instances`' B, so we can disregard `Ints`

tests/warn/i18661.scala

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Jacket[T]:
2+
sealed trait BodyType:
3+
sealed trait OrganType:
4+
case class Heart() extends Body.Organ
5+
case class Brain() extends Body.Organ
6+
object Organ extends OrganType
7+
sealed trait Organ
8+
object Body extends BodyType
9+
sealed trait Body
10+
11+
type AnyJacket = Jacket[?]
12+
type AnyBodyOrgan = AnyJacket#BodyType#Organ
13+
type AnyBodyOrganHeart = AnyJacket#BodyType#OrganType#Heart
14+
type AnyBodyOrganBrain = AnyJacket#BodyType#OrganType#Brain
15+
16+
def check( asr : AnyBodyOrgan ) : String =
17+
asr match
18+
case c : AnyBodyOrganHeart => "Heart"
19+
case s : AnyBodyOrganBrain => "Brain" // was: unreachable
20+
21+
val jacket = new Jacket[Unit]
22+
val heart = new jacket.Body.Organ.Heart()
23+
val brain = new jacket.Body.Organ.Brain()
24+
25+
@main
26+
def go =
27+
println( check( heart ) )
28+
println( check( brain ) )

0 commit comments

Comments
 (0)