From e34555f69e7cdd6d19d0d1ed969127f4ee65c36e Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 1 Feb 2017 17:18:13 +1100 Subject: Disallow taking a class tag of Nothing or Null. It seems in most cases this leads to weird behavior and cause confusing error messages later. It also means we cannot create an Array[Nothing], except by passing the classtag explicitly. --- tests/neg/i1802.scala | 4 ++-- tests/neg/i1907.scala | 7 +++++++ tests/neg/undet-classtag.scala | 5 +++++ 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 tests/neg/i1907.scala create mode 100644 tests/neg/undet-classtag.scala (limited to 'tests/neg') diff --git a/tests/neg/i1802.scala b/tests/neg/i1802.scala index 56da672a8..93e790f18 100644 --- a/tests/neg/i1802.scala +++ b/tests/neg/i1802.scala @@ -14,8 +14,8 @@ object Exception { def apply(x: Throwable): T = f(downcast(x).get) } - def mkThrowableCatcher[T](isDef: Throwable => Boolean, f: Throwable => T) = mkCatcher(isDef, f) + def mkThrowableCatcher[T](isDef: Throwable => Boolean, f: Throwable => T) = mkCatcher(isDef, f) // error: undetermined ClassTag - implicit def throwableSubtypeToCatcher[Ex <: Throwable: ClassTag, T](pf: PartialFunction[Ex, T]) = // error: cyclic reference + implicit def throwableSubtypeToCatcher[Ex <: Throwable: ClassTag, T](pf: PartialFunction[Ex, T]) = mkCatcher(pf.isDefinedAt _, pf.apply _) } diff --git a/tests/neg/i1907.scala b/tests/neg/i1907.scala new file mode 100644 index 000000000..6bc3bb56f --- /dev/null +++ b/tests/neg/i1907.scala @@ -0,0 +1,7 @@ +import java.io.File + +object Test { + Some(new File(".")) + .map(_.listFiles).getOrElse(Array.empty) // error: undetermined ClassTag + .map(_.listFiles) +} diff --git a/tests/neg/undet-classtag.scala b/tests/neg/undet-classtag.scala new file mode 100644 index 000000000..563596d14 --- /dev/null +++ b/tests/neg/undet-classtag.scala @@ -0,0 +1,5 @@ +object Test { + def f[T: reflect.ClassTag](x: T) = ??? + + f(???) // error: undetermined ClassTag +} -- cgit v1.2.3 From abbee9e28ef3f0150c9afa48f485ecc49e0e3787 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 1 Feb 2017 18:43:04 +1100 Subject: Update test file Updated with SI issues reported by Jason --- tests/neg/undet-classtag.scala | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests/neg') diff --git a/tests/neg/undet-classtag.scala b/tests/neg/undet-classtag.scala index 563596d14..dfe0eb2db 100644 --- a/tests/neg/undet-classtag.scala +++ b/tests/neg/undet-classtag.scala @@ -1,5 +1,27 @@ +import scala.reflect.ClassTag + object Test { def f[T: reflect.ClassTag](x: T) = ??? f(???) // error: undetermined ClassTag } + +// SI 9754 +object Program { + def test[T: ClassTag](x: T) = { + val arr = new Array[T](1) + println(arr.getClass) + println(x.getClass) + arr(0) = x + } + + def main(args: Array[String]): Unit = { + test(new Array[Nothing](0)) // error: undetermined ClassTag + } +} + +// SI 5353 +object t5353 { + if (false) Array("qwe") else Array() // error: undetermined ClassTag +} + -- cgit v1.2.3