Skip to content

Commit

Permalink
Make sure we don't construct invalid types if they're parameterised.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dwijnand committed Oct 17, 2023
1 parent 372e485 commit 7ccba02
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ object TypeOps:
else if symbol.is(Module) then
TermRef(this(tref.prefix), symbol.sourceModule)
else if (prefixTVar != null)
this(tref)
this(tref.applyIfParameterized(tref.typeParams.map(_ => WildcardType)))
else {
prefixTVar = WildcardType // prevent recursive call from assigning it
// e.g. tests/pos/i15029.more.scala, create a TypeVar for `Instances`' B, so we can disregard `Ints`
Expand Down
28 changes: 28 additions & 0 deletions tests/warn/i18661.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Jacket[T]:
sealed trait BodyType:
sealed trait OrganType:
case class Heart() extends Body.Organ
case class Brain() extends Body.Organ
object Organ extends OrganType
sealed trait Organ
object Body extends BodyType
sealed trait Body

type AnyJacket = Jacket[?]
type AnyBodyOrgan = AnyJacket#BodyType#Organ
type AnyBodyOrganHeart = AnyJacket#BodyType#OrganType#Heart
type AnyBodyOrganBrain = AnyJacket#BodyType#OrganType#Brain

def check( asr : AnyBodyOrgan ) : String =
asr match
case c : AnyBodyOrganHeart => "Heart"
case s : AnyBodyOrganBrain => "Brain" // warn

val jacket = new Jacket[Unit]
val heart = new jacket.Body.Organ.Heart()
val brain = new jacket.Body.Organ.Brain()

@main
def go =
println( check( heart ) )
println( check( brain ) )

0 comments on commit 7ccba02

Please sign in to comment.