Skip to content

Commit 462c388

Browse files
committed
Exclude self and super constructor calls from purity warnings
Don't issue a "pure expression does nothing in statement position" for self and super constructor calls. They are conceptually unit-returning in this position anyway.
1 parent 9a52dbd commit 462c388

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1917,7 +1917,8 @@ class Typer extends Namer
19171917
traverse(stats ++ rest)
19181918
case stat :: rest =>
19191919
val stat1 = typed(stat)(ctx.exprContext(stat, exprOwner))
1920-
if (!ctx.isAfterTyper && isPureExpr(stat1) && !stat1.tpe.isRef(defn.UnitClass))
1920+
if (!ctx.isAfterTyper && isPureExpr(stat1) &&
1921+
!stat1.tpe.isRef(defn.UnitClass) && !isSelfOrSuperConstrCall(stat1))
19211922
ctx.warning(em"a pure expression does nothing in statement position", stat.pos)
19221923
buf += stat1
19231924
traverse(rest)

tests/neg-custom-args/fatal-warnings/i2333.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@deprecated("bla", "2.11.0") class Foo {
2+
println("")
23
def this(x: Int) = this()
34
}
45

0 commit comments

Comments
 (0)