From 40e92d16605eb632c3c939abe770bd7b593355c5 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 6 Feb 2019 16:27:43 +0100 Subject: [PATCH] Another regression test for bad bounds This one comes from #5854. --- .../dotty/tools/dotc/CompilationTests.scala | 1 + tests/neg-custom-args/nullless.scala | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 tests/neg-custom-args/nullless.scala diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index 6469b2ba8a72..31ecfbcdd709 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -155,6 +155,7 @@ class CompilationTests extends ParallelTesting { compileFile("tests/neg-custom-args/overrideClass.scala", scala2Mode) + compileFile("tests/neg-custom-args/autoTuplingTest.scala", defaultOptions.and("-language:noAutoTupling")) + compileFile("tests/neg-custom-args/i1050.scala", defaultOptions.and("-strict")) + + compileFile("tests/neg-custom-args/nullless.scala", defaultOptions.and("-strict")) + compileFile("tests/neg-custom-args/nopredef.scala", defaultOptions.and("-Yno-predef")) + compileFile("tests/neg-custom-args/noimports.scala", defaultOptions.and("-Yno-imports")) + compileFile("tests/neg-custom-args/noimports2.scala", defaultOptions.and("-Yno-imports")) + diff --git a/tests/neg-custom-args/nullless.scala b/tests/neg-custom-args/nullless.scala new file mode 100644 index 000000000000..38845f5c3d8b --- /dev/null +++ b/tests/neg-custom-args/nullless.scala @@ -0,0 +1,40 @@ +object nullless { + trait LowerBound[T] { + type M >: T; + } + trait UpperBound[U] { + type M <: U; + } + lazy val nothing : Nothing = nothing + class Box[V](val v: V) + lazy val box : Box[UpperBound[String] & LowerBound[Int]] = new Box(nothing) + def upcast(t : box.v.M) : box.v.M = t // error // error under -strict + def main(args : Array[String]) : Unit = { + val zero : String = upcast(0) + println("...") + } +} +object bar { + trait Sub { + type M + type L <: M + type U >: M + type M2 >: L <: U + } + class Box[V](val v: V) + + class Caster[LL, UU] { + trait S2 { + type L = LL + type U = UU + } + final lazy val nothing: Nothing = nothing + final lazy val sub: S2 with Sub = nothing + final lazy val box : Box[S2 with Sub] = new Box(nothing) + def upcast(t: box.v.M2): box.v.M2 = t // error // error under -strict + } + def main(args : Array[String]) : Unit = { + val zero : String = (new Caster[Int,String]()).upcast(0) + println("...") + } +}