-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Don't allow wildcard types in constraints #12703
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 all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ff8659e
Don't allow wildcard types in constraints
odersky 1950246
Only drop wildcards for necesessary comparisons
odersky 8737254
drop all kinds of WildcardType under useNecessaryEither
odersky 0cdbff1
better bounds for wildcards in resultTypeApprox
odersky 5807fef
Avoid wildcard types in constraints
odersky 7020e78
Cleanup addOneBound logic
odersky be25c21
Verify that constraints do not contain wildcard types
odersky cfbe9e0
Cleanups
odersky 802c5d7
Streamline approximateWildcards logic
odersky ee939f1
Test assertion
odersky f0fe97f
Don't let wildcards enter constraints when adding type lambdas
odersky 5ed5ef8
Fix typo
odersky 9e2d250
Turn off "no wildcards in constraint" check
odersky 25e311f
Address review comments
odersky 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
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,31 @@ | ||
class F[A] | ||
object F { | ||
def apply[A](a: => A) = new F[A] | ||
} | ||
|
||
trait TC[A] { type Out } | ||
object TC { | ||
implicit def tc[A]: TC[A] { type Out = String } = ??? | ||
} | ||
|
||
// ==================================================================================== | ||
object Bug { | ||
final class CustomHook[A] { | ||
def blah(implicit tc: TC[A]): CustomHook[tc.Out] = ??? | ||
} | ||
|
||
def i: CustomHook[Int] = ??? | ||
val f = F(i.blah) | ||
f: F[CustomHook[String]] // error | ||
} | ||
|
||
// ==================================================================================== | ||
object Workaround { | ||
final class CustomHook[A] { | ||
def blah[B](implicit tc: TC[A] { type Out = B }): CustomHook[B] = ??? // raise type | ||
} | ||
|
||
def i: CustomHook[Int] = ??? | ||
val f = F(i.blah) | ||
f: F[CustomHook[String]] // works | ||
} |
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 to me why useNecessaryEither is treated specially here, is there a good justification or test case that illustrates this? Also in practice we also call necessaryEither when inferring GADTs:
https://github.com/lampepfl/dotty/blob/a82af21ff48ea07dbae042239286e5d80ef0e92e/compiler/src/dotty/tools/dotc/core/TypeComparer.scala#L1564
Should that condition also appear here? /cc @abgruszecki
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.
Yes, it probably should. Perhaps no GADT tests failed, because the interaction of GADTs and wildcards is undertested.
As a side remark, I'm not sure when exactly we should consider
useNecessaryEither
in separation from the GADT mode. The name doesn't help either in reminding that we should do both. Perhaps we should hide this condition behind a definition and renameuseNecessaryEither
?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 believe 12677 is the test case that fails otherwise.
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.
Not sure about GADT inference. Does it even come up?
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 verified that all tests pass with or without the added condition
ctx.mode.is(Mode.GadtConstraintInference)
. Someone else could go to the bottom of this in a separate PR.