-
Notifications
You must be signed in to change notification settings - Fork 21
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
type aliases + variance checks: to dealias or not to dealias (and: dealiasing loses annotations on type arguments) #8079
Comments
Imported From: https://issues.scala-lang.org/browse/SI-8079?orig=1 |
@paulp said: illegal inheritance from final class Optional
[error] trait Optional[+T] extends java.util.Optional[T @uV]
[error] ^
[error] one error found Without fixing this there is no way to treat java.util.Optional (for instance - as one example among endless) as the covariant type it should be without adding an uncheckedVariance annotation at every single use site until you die. Of course there's no point in that, you can write _ <: A at every single use site until you die, and that's probably shorter. scala> import scala.annotation.unchecked.{ uncheckedVariance => uV }
import scala.annotation.unchecked.{uncheckedVariance=>uV}
scala> type Opt[+A] = java.util.Optional[A @uV]
defined type alias Opt
scala> class A[+T](val x: Opt[T])
<console>:9: error: covariant type T occurs in invariant position in type => Opt[T] of value x
class A[+T](val x: Opt[T])
^
scala> class A[+T](val x: java.util.Optional[T])
<console>:8: error: covariant type T occurs in invariant position in type => java.util.Optional[T] of value x
class A[+T](val x: java.util.Optional[T])
^
scala> class A[+T](val x: Option[T])
defined class A
scala> class A[+T](val x: java.util.Optional[_ <: T])
defined class A
scala> class A[+T](val x: Opt[T @uV])
defined class A |
@retronym said: I'm going to try to pass through all annotations to see if anything breaks or gets slower. Hopefully that change will also sort out this ticket. |
@paulp said (edited on Dec 14, 2013 4:47:56 PM UTC): |
@paulp said:
In case you haven't tried that yet, I did. Here you go. https://github.com/paulp/scala/tree/pr/keep-type-annotations Although the branch is prefixed with "pr/" I won't be sending a pull request because I'm not interested in dealing with the two failures. But the branch is some evidence the change is easily makable. |
@retronym said: |
@retronym said:
If we omit the checks on the RHS because the alias is sufficiently private, we clearly must check expansions. For example, the following is unsound but was allowed in Scala 2.7: trait C[-I] {
private[this] type X = C[I]
def f2(b: X): Unit
} Intuitively, I think we only need to check in one place. But I'll give it some more thought. |
@samskivert said: I'm happy to provide what support I can in getting this resolved, but it seems like the right fix here is something that can only be decided by someone with intimate knowledge of the nefarious machinations of the compiler. |
@paulp said (edited on Apr 18, 2016 2:54:15 PM UTC): |
@SethTisue said: |
There's no reason CovTrait should be afforded any privilege above CovAlias.
The text was updated successfully, but these errors were encountered: