Skip to content

Commit 2dc40cc

Browse files
committed
Merge pull request scala#4380 from retronym/ticket/9020
SI-9020 Avoid spurious value discarding warning post-typer
2 parents 4f05b19 + bf01acd commit 2dc40cc

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/compiler/scala/tools/nsc/typechecker/Typers.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,11 +1039,11 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
10391039
// to non-continuation types.
10401040
if (tree.tpe <:< AnyTpe) pt.dealias match {
10411041
case TypeRef(_, UnitClass, _) => // (12)
1042-
if (settings.warnValueDiscard)
1042+
if (!isPastTyper && settings.warnValueDiscard)
10431043
context.warning(tree.pos, "discarded non-Unit value")
10441044
return typedPos(tree.pos, mode, pt)(Block(List(tree), Literal(Constant(()))))
10451045
case TypeRef(_, sym, _) if isNumericValueClass(sym) && isNumericSubType(tree.tpe, pt) =>
1046-
if (settings.warnNumericWiden)
1046+
if (!isPastTyper && settings.warnNumericWiden)
10471047
context.warning(tree.pos, "implicit numeric widening")
10481048
return typedPos(tree.pos, mode, pt)(Select(tree, "to" + sym.name))
10491049
case _ =>

test/files/pos/t9020.flags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Ywarn-value-discard -Xfatal-warnings

test/files/pos/t9020.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
trait ValueDiscard[@specialized U] {
2+
def u: U
3+
}
4+
/* Was:
5+
scalac-hash v2.11.5 -Ywarn-value-discard test/files/pos/t9020.scala
6+
test/files/pos/t9020.scala:2: warning: discarded non-Unit value
7+
def u: U
8+
^
9+
one warning found
10+
*/

0 commit comments

Comments
 (0)