forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure we don't construct invalid types if they're parameterised.
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
Showing
2 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ) ) |