-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Prune impossible types from exhaustivity checker #3574
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
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
object PathVariantDefns { | ||
sealed trait AtomBase { | ||
sealed trait Atom | ||
case class Zero(value: String) extends Atom | ||
} | ||
|
||
trait Atom1 extends AtomBase { | ||
case class One(value: String) extends Atom | ||
} | ||
|
||
trait Atom2 extends AtomBase { | ||
case class Two(value: String) extends Atom | ||
} | ||
|
||
object Atoms01 extends AtomBase with Atom1 { | ||
def f = { | ||
val a: Atom = null | ||
a match { | ||
case Zero(x) => ??? | ||
case One(x) => ??? | ||
// match may not be exhaustive. | ||
// It would fail on: PathVariantDefns.Atom2 & PathVariantDefns.Atoms01.type(PathVariantDefns.Atoms01).Two(_) | ||
} | ||
} | ||
} | ||
|
||
object Atoms02 extends AtomBase with Atom2 { | ||
def f = { | ||
val a: Atom = null | ||
a match { | ||
case Zero(x) => ??? | ||
case Two(x) => ??? | ||
// match may not be exhaustive. | ||
// It would fail on: PathVariantDefns.Atom1 & PathVariantDefns.Atoms02.type(PathVariantDefns.Atoms02).One(_) | ||
} | ||
} | ||
} | ||
} |
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.
In the check, there's a facility named
implementability
from a contributor which does more or less the same thing. What do you think we can generalise/adaptimplementability
to handle the case?In particular, I think it's good to rename it to
def inhabited(tp: Type): Boolean
, and it should be able to handle the current case as well. WDYT?Uh oh!
There was an error while loading. Please reload this page.
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 think
implementability
computes if a type can be implemented by other types (singleton types can't!), whileinhabited
would need to check if there could actually exists an instance of that type, so I'm not sure two logics can be merged.@AleksanderBG what's your opinion on that?
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 think
implementability
should be refactored to have the semantics ofinhabited
. According to the core algorithm of exhaustivity check, it should only depend on the semantics ofdef inhabited(tp: Type): Boolean
.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.
@OlivierBlanvillain I believe @liufengyun is correct - the function can be safely changed to check if a type is inhabited instead. This won't change the result for and-types, which is the only result
intersectUnrelatedAtomicTypes
should care about. I considered a similar refactoring myself when working on #3454. With the benefit of hindsight, type inhabitation is a far more generic notion and I should've tried to implement it from the beginning.