From 100d82697b2ec747cfc955a9869b8c3d2900f1a2 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sun, 22 Jul 2012 22:16:03 -0700 Subject: Improve unchecked warnings. Spurious test was not good. Better test avoids suppressing some legitimate warnings. Review by @moors. --- src/compiler/scala/tools/nsc/typechecker/Infer.scala | 12 +++++++----- test/files/neg/unchecked2.check | 19 +++++++++++++++++++ test/files/neg/unchecked2.flags | 1 + test/files/neg/unchecked2.scala | 8 ++++++++ test/files/pos/t1439.scala | 2 +- 5 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 test/files/neg/unchecked2.check create mode 100644 test/files/neg/unchecked2.flags create mode 100644 test/files/neg/unchecked2.scala diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index 960c210649..1988051020 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -1278,8 +1278,10 @@ trait Infer { } else { for (arg <- args) { if (sym == ArrayClass) check(arg, bound) - else if (arg.typeArgs.nonEmpty) () // avoid spurious warnings with higher-kinded types - else if (sym == NonLocalReturnControlClass) () // no way to suppress unchecked warnings on try/catch + // avoid spurious warnings with higher-kinded types + else if (arg.typeArgs exists (_.typeSymbol.isTypeParameterOrSkolem)) () + // no way to suppress unchecked warnings on try/catch + else if (sym == NonLocalReturnControlClass) () else arg match { case TypeRef(_, sym, _) if isLocalBinding(sym) => ; @@ -1423,7 +1425,7 @@ trait Infer { ) // Intentionally *not* using `Type#typeSymbol` here, which would normalize `tp` - // and collect symbols from the result type of any resulting `PolyType`s, which + // and collect symbols from the result type of any resulting `PolyType`s, which // are not free type parameters of `tp`. // // Contrast with `isFreeTypeParamNoSkolem`. @@ -1456,7 +1458,7 @@ trait Infer { def inferExprAlternative(tree: Tree, pt: Type) = tree.tpe match { case OverloadedType(pre, alts) => tryTwice { isSecondTry => val alts0 = alts filter (alt => isWeaklyCompatible(pre.memberType(alt), pt)) - val noAlternatives = alts0.isEmpty + val noAlternatives = alts0.isEmpty val alts1 = if (noAlternatives) alts else alts0 //println("trying "+alts1+(alts1 map (_.tpe))+(alts1 map (_.locationString))+" for "+pt) @@ -1614,7 +1616,7 @@ trait Infer { val saved = context.state var fallback = false context.setBufferErrors() - // We cache the current buffer because it is impossible to + // We cache the current buffer because it is impossible to // distinguish errors that occurred before entering tryTwice // and our first attempt in 'withImplicitsDisabled'. If the // first attempt fails we try with implicits on *and* clean diff --git a/test/files/neg/unchecked2.check b/test/files/neg/unchecked2.check new file mode 100644 index 0000000000..2c0be9ce00 --- /dev/null +++ b/test/files/neg/unchecked2.check @@ -0,0 +1,19 @@ +unchecked2.scala:2: error: non variable type-argument Int in type Option[Int] is unchecked since it is eliminated by erasure + Some(123).isInstanceOf[Option[Int]] + ^ +unchecked2.scala:3: error: non variable type-argument String in type Option[String] is unchecked since it is eliminated by erasure + Some(123).isInstanceOf[Option[String]] + ^ +unchecked2.scala:4: error: non variable type-argument List[String] in type Option[List[String]] is unchecked since it is eliminated by erasure + Some(123).isInstanceOf[Option[List[String]]] + ^ +unchecked2.scala:5: error: non variable type-argument List[Int => String] in type Option[List[Int => String]] is unchecked since it is eliminated by erasure + Some(123).isInstanceOf[Option[List[Int => String]]] + ^ +unchecked2.scala:6: error: non variable type-argument (String, Double) in type Option[(String, Double)] is unchecked since it is eliminated by erasure + Some(123).isInstanceOf[Option[(String, Double)]] + ^ +unchecked2.scala:7: error: non variable type-argument String => Double in type Option[String => Double] is unchecked since it is eliminated by erasure + Some(123).isInstanceOf[Option[String => Double]] + ^ +6 errors found diff --git a/test/files/neg/unchecked2.flags b/test/files/neg/unchecked2.flags new file mode 100644 index 0000000000..144ddac9d3 --- /dev/null +++ b/test/files/neg/unchecked2.flags @@ -0,0 +1 @@ +-unchecked -Xfatal-warnings diff --git a/test/files/neg/unchecked2.scala b/test/files/neg/unchecked2.scala new file mode 100644 index 0000000000..a2e757e1dc --- /dev/null +++ b/test/files/neg/unchecked2.scala @@ -0,0 +1,8 @@ +object Test { + Some(123).isInstanceOf[Option[Int]] + Some(123).isInstanceOf[Option[String]] + Some(123).isInstanceOf[Option[List[String]]] + Some(123).isInstanceOf[Option[List[Int => String]]] + Some(123).isInstanceOf[Option[(String, Double)]] + Some(123).isInstanceOf[Option[String => Double]] +} diff --git a/test/files/pos/t1439.scala b/test/files/pos/t1439.scala index 68a7332b2a..0efcc74b65 100644 --- a/test/files/pos/t1439.scala +++ b/test/files/pos/t1439.scala @@ -2,7 +2,7 @@ class View[C[A]] { } object Test { - null match { + (null: Any) match { case v: View[_] => } } -- cgit v1.2.3