From d04cd7b39107fb7cb817a08265724c00043b1396 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Wed, 24 Sep 2014 10:31:33 -0700 Subject: SI-8861 Handle alias when probing for Any If args to a method are alias types, dealias to see if they contain Any before warning about inferring it. Similarly for return and expected types. --- test/files/pos/t8861.flags | 1 + test/files/pos/t8861.scala | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 test/files/pos/t8861.flags create mode 100644 test/files/pos/t8861.scala (limited to 'test/files/pos') diff --git a/test/files/pos/t8861.flags b/test/files/pos/t8861.flags new file mode 100644 index 0000000000..99a6391058 --- /dev/null +++ b/test/files/pos/t8861.flags @@ -0,0 +1 @@ +-Xlint:infer-any -Xfatal-warnings diff --git a/test/files/pos/t8861.scala b/test/files/pos/t8861.scala new file mode 100644 index 0000000000..816d15700e --- /dev/null +++ b/test/files/pos/t8861.scala @@ -0,0 +1,11 @@ + +trait Test { + type R = PartialFunction[Any, Unit] + + val x: R = { case "" => } + val y: R = { case "" => } + + val z: R = x orElse y + val zz = x orElse y +} + -- cgit v1.2.3 From bf01acd6143552be8a173472a839dfcdee27697c Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Thu, 12 Mar 2015 15:25:14 -0700 Subject: SI-9020 Avoid spurious value discarding warning post-typer Typechecking during the specialization phase was emitting a bogus warning about value discarding. Such warnings in the typer should be guarded by `!isPastTyper` to restrict the analysis to the code the user originally wrote, rather than the results of later typechecking. I've made this change to the value discarding warning. I've also changed a numeric widening warning in the vicinity, although I do not have a test case for that. --- src/compiler/scala/tools/nsc/typechecker/Typers.scala | 4 ++-- test/files/pos/t9020.flags | 1 + test/files/pos/t9020.scala | 10 ++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 test/files/pos/t9020.flags create mode 100644 test/files/pos/t9020.scala (limited to 'test/files/pos') diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 3a85d16f55..7ef739e711 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1039,11 +1039,11 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper // to non-continuation types. if (tree.tpe <:< AnyTpe) pt.dealias match { case TypeRef(_, UnitClass, _) => // (12) - if (settings.warnValueDiscard) + if (!isPastTyper && settings.warnValueDiscard) context.warning(tree.pos, "discarded non-Unit value") return typedPos(tree.pos, mode, pt)(Block(List(tree), Literal(Constant(())))) case TypeRef(_, sym, _) if isNumericValueClass(sym) && isNumericSubType(tree.tpe, pt) => - if (settings.warnNumericWiden) + if (!isPastTyper && settings.warnNumericWiden) context.warning(tree.pos, "implicit numeric widening") return typedPos(tree.pos, mode, pt)(Select(tree, "to" + sym.name)) case _ => diff --git a/test/files/pos/t9020.flags b/test/files/pos/t9020.flags new file mode 100644 index 0000000000..efb2dd3e6f --- /dev/null +++ b/test/files/pos/t9020.flags @@ -0,0 +1 @@ +-Ywarn-value-discard -Xfatal-warnings diff --git a/test/files/pos/t9020.scala b/test/files/pos/t9020.scala new file mode 100644 index 0000000000..16e31e2572 --- /dev/null +++ b/test/files/pos/t9020.scala @@ -0,0 +1,10 @@ +trait ValueDiscard[@specialized U] { + def u: U +} +/* Was: +scalac-hash v2.11.5 -Ywarn-value-discard test/files/pos/t9020.scala +test/files/pos/t9020.scala:2: warning: discarded non-Unit value + def u: U + ^ +one warning found +*/ -- cgit v1.2.3