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/neg/boundspropagation.scala b/tests/neg/boundspropagation.scala new file mode 100644 index 000000000000..560d5416c17b --- /dev/null +++ b/tests/neg/boundspropagation.scala @@ -0,0 +1,26 @@ +// scalac fails for test2/3 +// dotc fails 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 + } +} diff --git a/tests/pending/pos/boundspropagation.scala b/tests/pending/pos/boundspropagation.scala index 560d5416c17b..23f998a34454 100644 --- a/tests/pending/pos/boundspropagation.scala +++ b/tests/pending/pos/boundspropagation.scala @@ -1,5 +1,5 @@ // scalac fails for test2/3 -// dotc fails for all three +// dotc used to fail for all three object test1 { class Tree[-T >: Null] @@ -8,7 +8,7 @@ object test1 { case y: Tree[_] => y } } -object test2 { +/*object test2 { class Tree[T >: Null] @@ -22,5 +22,6 @@ object test3 { def f(x: Any): Tree[Null] = x match { case y: Tree[_] => y - } + } } +*/