Skip to content

Commit a50f046

Browse files
committed
Move methods from UnusedUtil to Applications
1 parent 5a884b2 commit a50f046

File tree

3 files changed

+17
-34
lines changed

3 files changed

+17
-34
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import NameKinds.DefaultGetterName
2424
import ProtoTypes._
2525
import EtaExpansion._
2626
import Inferencing._
27-
import UnusedUtil._
2827

2928
import collection.mutable
3029
import config.Printers.{overload, typr, unapp}
@@ -1540,6 +1539,23 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
15401539
harmonizedElems
15411540
}
15421541

1542+
/** Transforms the tree into a its default tree.
1543+
* Performed to shrink the tree that is known to be erased later.
1544+
*/
1545+
protected def normalizeUnusedExpr(tree: Tree, msg: String)(implicit ctx: Context): Tree = {
1546+
if (!isPureExpr(tree))
1547+
ctx.warning(msg + "This expression will not be evaluated.", tree.pos)
1548+
defaultValue(tree.tpe)
1549+
}
1550+
1551+
/** Transforms the rhs tree into a its default tree if it is in an `unused` val/def.
1552+
* Performed to shrink the tree that is known to be erased later.
1553+
*/
1554+
protected def normalizeUnusedRhs(rhs: Tree, sym: Symbol)(implicit ctx: Context) = {
1555+
if (sym.is(Unused) && rhs.tpe.exists) normalizeUnusedExpr(rhs, "Expression is on the RHS of an `unused` " + sym.showKind + ". ")
1556+
else rhs
1557+
}
1558+
15431559
/** If all `types` are numeric value types, and they are not all the same type,
15441560
* pick a common numeric supertype and widen any constant types in `tpes` to it.
15451561
* If the resulting types are all the same, return them instead of the original ones.

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import dotty.tools.dotc.transform.Erasure.Boxing
2929
import util.Positions._
3030
import util.common._
3131
import util.{Property, SourcePosition}
32-
import UnusedUtil._
3332

3433
import collection.mutable
3534
import annotation.tailrec

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

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)