-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix unreachable warning in deeply nested sealed hierarchy #18706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dwijnand
merged 4 commits into
scala:main
from
dwijnand:nested-nested-nested-in-generic-parent
Oct 20, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9c92162
Vulpix: Remove unused logStackTrace & downstream usages
dwijnand b843332
Vulpix: Allow warn tests to have no warnings
dwijnand 372e485
Vulpix: Skip empty lines
dwijnand 9460b7d
Fix unreachable warning in deeply nested sealed hierarchy
dwijnand File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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" // was: unreachable | ||
|
||
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 ) ) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear why this is correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to detail it in the commit message (9460b7d) - given something like:
As we map over the type
Jacket.this.BodyType
we don't want to take the raw typeJacket
, stripped from its ThisType wrapper, and have it be the prefix ofBodyType
, because we would then getJacket#BodyType
which is ill-formed. Instead we mean to refer to any the BodyType nested class of any Jacket:Jacket[?]#BodyType
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation. I now see the type will be upper bound for
prefixTVar
, so it's harmless.