From 2481b4efeff86432523cbe0d4ee90f1ff1aecd38 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 29 Sep 2020 10:14:02 +0200 Subject: [PATCH 1/2] Fix #8988: Remove @uncheckedVariance in simplify --- compiler/src/dotty/tools/dotc/core/TypeOps.scala | 3 +++ compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala | 3 +++ compiler/test/dotc/pos-test-pickling.blacklist | 3 +++ tests/neg/i8988.check | 5 +++++ tests/neg/i8988.scala | 3 +++ 5 files changed, 17 insertions(+) create mode 100644 tests/neg/i8988.check create mode 100644 tests/neg/i8988.scala diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala index 73bdcad169c5..bb1f5af26dc7 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -152,6 +152,9 @@ object TypeOps: simplify(l, theMap) & simplify(r, theMap) case OrType(l, r) if !ctx.mode.is(Mode.Type) => simplify(l, theMap) | simplify(r, theMap) + case AnnotatedType(parent, annot) + if !ctx.mode.is(Mode.Type) && annot.symbol == defn.UncheckedVarianceAnnot => + simplify(parent, theMap) case _: MatchType => val normed = tp.tryNormalize if (normed.exists) normed else mapOver diff --git a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala index ade70b71dd7c..58149b76b663 100644 --- a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -56,6 +56,9 @@ class PlainPrinter(_ctx: Context) extends Printer { homogenize(tp1) & homogenize(tp2) case OrType(tp1, tp2) => homogenize(tp1) | homogenize(tp2) + case AnnotatedType(parent, annot) + if !ctx.mode.is(Mode.Type) && annot.symbol == defn.UncheckedVarianceAnnot => + homogenize(parent) case tp: SkolemType => homogenize(tp.info) case tp: LazyRef => diff --git a/compiler/test/dotc/pos-test-pickling.blacklist b/compiler/test/dotc/pos-test-pickling.blacklist index 97a453f8508a..cc6b0813f0a0 100644 --- a/compiler/test/dotc/pos-test-pickling.blacklist +++ b/compiler/test/dotc/pos-test-pickling.blacklist @@ -46,3 +46,6 @@ i7757.scala # splice type tag dealiased in this reference i8651b.scala + +# uneliminated @uncheckedVariance after pickling +annot-bootstrap.scala diff --git a/tests/neg/i8988.check b/tests/neg/i8988.check new file mode 100644 index 000000000000..8b14c32a3497 --- /dev/null +++ b/tests/neg/i8988.check @@ -0,0 +1,5 @@ +-- [E007] Type Mismatch Error: tests/neg/i8988.scala:3:17 -------------------------------------------------------------- +3 |val zs: String = ys // error: (but type should not mention @uncheckedVariance) + | ^^ + | Found: (ys : List[Int]) + | Required: String diff --git a/tests/neg/i8988.scala b/tests/neg/i8988.scala new file mode 100644 index 000000000000..c3da86bfb713 --- /dev/null +++ b/tests/neg/i8988.scala @@ -0,0 +1,3 @@ +val xs = List(1, 2, 3) +val ys = xs.tail +val zs: String = ys // error: (but type should not mention @uncheckedVariance) From f07c47782612dcf62ad5c80abad907395a756f39 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 29 Sep 2020 11:45:57 +0200 Subject: [PATCH 2/2] Exclude annot-bootstrap also from FromTasty tests --- compiler/test/dotc/pos-from-tasty.blacklist | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/test/dotc/pos-from-tasty.blacklist b/compiler/test/dotc/pos-from-tasty.blacklist index 1fac00b403ab..ef9db525b38f 100644 --- a/compiler/test/dotc/pos-from-tasty.blacklist +++ b/compiler/test/dotc/pos-from-tasty.blacklist @@ -13,3 +13,6 @@ i7087.scala # Nullability nullable.scala notNull.scala + +# cyclic reference involving @uncheckedVariance +annot-bootstrap.scala