Skip to content

Commit 2267712

Browse files
committed
Don't warn if impure expressions are passed to erased vals
`erased` is really the same thing as `lazy` or by-name. The semantics implies it will not be evaluated. So it is pointless to warn if an impure expression is passed to an erased val or parameter. Moreover, erased initializers are often complex expressions - after all if they were not, why erase them in the first place? These expressions are almost never recognized as pure given the weak effect checking we currently have. So the warnings are issued in the common case, which is bad.
1 parent 71f3aca commit 2267712

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

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

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
799799
}
800800
app match {
801801
case Apply(fun, args) if fun.tpe.widen.isErasedMethod =>
802-
tpd.cpy.Apply(app)(fun = fun, args = args.map(arg => normalizeErasedExpr(arg, "This argument is given to an erased parameter. ")))
802+
tpd.cpy.Apply(app)(fun = fun, args = args.map(arg => defaultValue(arg.tpe)))
803803
case _ => app
804804
}
805805
}
@@ -1567,22 +1567,11 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
15671567
harmonizedElems
15681568
}
15691569

1570-
/** Transforms the tree into a its default tree.
1571-
* Performed to shrink the tree that is known to be erased later.
1572-
*/
1573-
protected def normalizeErasedExpr(tree: Tree, msg: String)(implicit ctx: Context): Tree = {
1574-
if (!isPureExpr(tree))
1575-
ctx.warning(msg + "This expression will not be evaluated.", tree.pos)
1576-
defaultValue(tree.tpe)
1577-
}
1578-
15791570
/** Transforms the rhs tree into a its default tree if it is in an `erased` val/def.
15801571
* Performed to shrink the tree that is known to be erased later.
15811572
*/
1582-
protected def normalizeErasedRhs(rhs: Tree, sym: Symbol)(implicit ctx: Context) = {
1583-
if (sym.is(Erased) && rhs.tpe.exists) normalizeErasedExpr(rhs, "Expression is on the RHS of an `erased` " + sym.showKind + ". ")
1584-
else rhs
1585-
}
1573+
protected def normalizeErasedRhs(rhs: Tree, sym: Symbol)(implicit ctx: Context) =
1574+
if (sym.is(Erased) && rhs.tpe.exists) defaultValue(rhs.tpe) else rhs
15861575

15871576
/** If all `types` are numeric value types, and they are not all the same type,
15881577
* pick a common numeric supertype and widen any constant types in `tpes` to it.

0 commit comments

Comments
 (0)