-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Make singleton operations covariant #14452
Make singleton operations covariant #14452
Conversation
c59038d
to
d913504
Compare
The problem is that covariance and contravariance encourage the compiler to widen. I wonder if it has any unwanted side effect. |
I think covariance allows the compiler to widen when it is actually useful. In my experiments with singleton ops, the impossibility to compare operations containing skolems or term references is a big blocker. We definitely need a way to preserve precise types and I am experimenting with different possibilities (such as an |
I'll try this branch on my code-base to see if it has any unwanted effect. I'll reply when I'm done. |
This looks very reasonable to me. Seems intuitive that I don't feel comfortable marking the PR as approved myself, because I don't actively contribute to the repo, and I might not have the full picture. But I do otherwise approve of the change! Unless we have a specific counter-example of how covariance might result in unexpected widenings and break things right now, then I think that as long as tests pass, we can merge this. One thing you could try to do to make sure that this works is to compile the community build, or maybe just a few projects that make heavy use of singleton ops (e.g. tf-dotty -- you can ping me if you need any help with this). |
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 checked this branch effect on my library, and nothing "bad" happened.
The implementation LGTM.
|
The appropriate approval pun would be |
@MaximeKjaer |
@@ -42,7 +42,7 @@ object any: | |||
* @syntax markdown | |||
*/ | |||
@experimental | |||
type IsConst[X] <: Boolean | |||
type IsConst[+X] <: 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.
Should we consider leaving this one invariant? IsConst[1]
is true
, but IsConst[Int]
is false
…s-covariance Revert #14452 and make compile-time operations on stable arguments stable
Currently, this does not compile:
because
(x: X) * Y
is not a subtype ofX * Y
.Making the compiletime operation types covariant in their arguments would enable this.