From 06bea02d6c6b0e3202ee2f6472a79cab384bdfa0 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 17 Nov 2014 16:10:21 +0100 Subject: [PATCH 1/2] Fix bounds propagation When instantiating with a wildcard argument, take formal parameter bounds into account. --- src/dotty/tools/dotc/core/TypeApplications.scala | 4 +++- test/dotc/tests.scala | 1 + tests/{pending/pos => neg}/boundspropagation.scala | 0 3 files changed, 4 insertions(+), 1 deletion(-) rename tests/{pending/pos => neg}/boundspropagation.scala (100%) diff --git a/src/dotty/tools/dotc/core/TypeApplications.scala b/src/dotty/tools/dotc/core/TypeApplications.scala index bf756facfa28..81328b9940b6 100644 --- a/src/dotty/tools/dotc/core/TypeApplications.scala +++ b/src/dotty/tools/dotc/core/TypeApplications.scala @@ -200,8 +200,10 @@ class TypeApplications(val self: Type) extends AnyVal { */ final def toBounds(tparam: Symbol)(implicit ctx: Context): TypeBounds = self match { case self: TypeBounds => // this can happen for wildcard args - self + self & tparam.info.bounds case _ => + // no within-bounds check done here because of risk of cycles. Thsi is done later + // for source generated types using checkBounds. val v = tparam.variance if (v > 0 && !(tparam is Local) && !(tparam is ExpandedTypeParam)) TypeBounds.upper(self) else if (v < 0 && !(tparam is Local) && !(tparam is ExpandedTypeParam)) TypeBounds.lower(self) diff --git a/test/dotc/tests.scala b/test/dotc/tests.scala index 966c231e4cac..bf127d7ae623 100644 --- a/test/dotc/tests.scala +++ b/test/dotc/tests.scala @@ -102,6 +102,7 @@ class tests extends CompilerTest { @Test def neg_typetest = compileFile(negDir, "typetest", xerrors = 1) @Test def neg_t1569_failedAvoid = compileFile(negDir, "t1569-failedAvoid", xerrors = 1) @Test def neg_cycles = compileFile(negDir, "cycles", xerrors = 6) + @Test def neg_boundspropagation = compileFile(negDir, "boundspropagation", xerrors = 2) @Test def dotc = compileDir(dotcDir + "tools/dotc", twice)(allowDeepSubtypes) @Test def dotc_ast = compileDir(dotcDir + "tools/dotc/ast", twice) diff --git a/tests/pending/pos/boundspropagation.scala b/tests/neg/boundspropagation.scala similarity index 100% rename from tests/pending/pos/boundspropagation.scala rename to tests/neg/boundspropagation.scala From 1c6ce936550a08b3d505375548c4a19efd9fead3 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 17 Nov 2014 16:17:54 +0100 Subject: [PATCH 2/2] Updated comment in test --- tests/pending/pos/boundspropagation.scala | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/pending/pos/boundspropagation.scala diff --git a/tests/pending/pos/boundspropagation.scala b/tests/pending/pos/boundspropagation.scala new file mode 100644 index 000000000000..23f998a34454 --- /dev/null +++ b/tests/pending/pos/boundspropagation.scala @@ -0,0 +1,27 @@ +// scalac fails for test2/3 +// dotc used to fail for all three +object test1 { + class Tree[-T >: Null] + + + def f(x: Any): Tree[Null] = x match { + case y: Tree[_] => y + } +} +/*object test2 { + class Tree[T >: Null] + + + def f(x: Any): Tree[Null] = x match { + case y: Tree[_] => y + } +} +object test3 { + class Tree[+T >: Null] + + + def f(x: Any): Tree[Null] = x match { + case y: Tree[_] => y + } +} +*/