diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2014-09-26 09:24:50 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2016-08-18 11:18:47 +1000 |
commit | 036a9bbd0be2b71fc9d60954fd0b1b64c9a181af (patch) | |
tree | 714e23d5e4da45ae1fd6badb1f3d90a40dd426dd /test | |
parent | 4e564efb04e508ccc0f479cf1a25331501927d88 (diff) | |
download | scala-036a9bbd0be2b71fc9d60954fd0b1b64c9a181af.tar.gz scala-036a9bbd0be2b71fc9d60954fd0b1b64c9a181af.tar.bz2 scala-036a9bbd0be2b71fc9d60954fd0b1b64c9a181af.zip |
SI-8079 Only expand local aliases during variance checks
We've been flip-flopping on this one through the years, right
now we issue an two errors for the enclosed test.
After this commit, variance validation only expands aliases that
are `{private,protected}[this]`. The rest need not be expanded,
as we have already variance validated the RHS of the alias.
It also removes a seemingly incorrect check in `isLocalOnly`.
This also means that we can use `@uncheckedVariance` to create
variant type aliases for Java interfaces.
However, if such a type alias is declared private local, it
*will* be expanded. That shouldn't be a problem, other than
for the fact that we run through an as-seen-from that strips
the `@uV` annotations in the type expansion. This has been
recorded in a pending test.
Diffstat (limited to 'test')
-rw-r--r-- | test/files/neg/t8079a.check | 4 | ||||
-rw-r--r-- | test/files/neg/t8079a.scala | 4 | ||||
-rw-r--r-- | test/files/neg/variances.check | 2 | ||||
-rw-r--r-- | test/files/pos/t8079b.scala | 7 | ||||
-rw-r--r-- | test/pending/pos/t8079c.scala | 7 |
5 files changed, 23 insertions, 1 deletions
diff --git a/test/files/neg/t8079a.check b/test/files/neg/t8079a.check new file mode 100644 index 0000000000..6bbe78afa6 --- /dev/null +++ b/test/files/neg/t8079a.check @@ -0,0 +1,4 @@ +t8079a.scala:3: error: contravariant type I occurs in covariant position in type C.this.X of value b + def f2(b: X): Unit + ^ +one error found diff --git a/test/files/neg/t8079a.scala b/test/files/neg/t8079a.scala new file mode 100644 index 0000000000..4997ea282e --- /dev/null +++ b/test/files/neg/t8079a.scala @@ -0,0 +1,4 @@ +trait C[-I] { + private[this] type X = C[I] + def f2(b: X): Unit +} diff --git a/test/files/neg/variances.check b/test/files/neg/variances.check index cb1a60a632..3c1545a375 100644 --- a/test/files/neg/variances.check +++ b/test/files/neg/variances.check @@ -19,7 +19,7 @@ variances.scala:74: error: covariant type A occurs in contravariant position in variances.scala:89: error: covariant type T occurs in invariant position in type T of type A type A = T ^ -variances.scala:90: error: covariant type T occurs in contravariant position in type => test.TestAlias.B[C.this.A] of method foo +variances.scala:90: error: covariant type A occurs in contravariant position in type => test.TestAlias.B[C.this.A] of method foo def foo: B[A] ^ 8 errors found diff --git a/test/files/pos/t8079b.scala b/test/files/pos/t8079b.scala new file mode 100644 index 0000000000..f3b7b78077 --- /dev/null +++ b/test/files/pos/t8079b.scala @@ -0,0 +1,7 @@ +trait F1[/* - */T, /* + */ R] + +object Test { + import scala.annotation.unchecked._ + type VariantF1[-T, +R] = F1[T @uncheckedVariance, R @uncheckedVariance] + trait C[+T] { def foo: VariantF1[Any, T] } +} diff --git a/test/pending/pos/t8079c.scala b/test/pending/pos/t8079c.scala new file mode 100644 index 0000000000..ae7f37e2bf --- /dev/null +++ b/test/pending/pos/t8079c.scala @@ -0,0 +1,7 @@ +trait F1[/* - */T, /* + */ R] + +object Test { + import scala.annotation.unchecked._ + private[this] type VariantF1[-T, +R] = F1[T @uncheckedVariance, R @uncheckedVariance] + trait C[+T] { def foo: VariantF1[Any, T] } +} |