Skip to content

Commit 679427b

Browse files
committed
Move checks on symbol falgs and types to Checking
1 parent 7c9f61d commit 679427b

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

compiler/src/dotty/tools/dotc/transform/UnusedChecks.scala

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,17 @@ class UnusedChecks extends MiniPhase {
2424

2525
/* Tree transform */
2626

27-
override def transformTypeDef(tree: TypeDef)(implicit ctx: Context): tree.type = {
28-
if (tree.symbol.is(UnusedType))
29-
ctx.error(tree.symbol.showKind + " cannot be unused", tree.pos)
30-
tree
31-
}
32-
3327
override def transformApply(tree: Apply)(implicit ctx: Context): tree.type = {
3428
if (!isUnusedContext && !tree.symbol.is(Unused) && !tree.fun.tpe.widen.isUnusedMethod)
3529
tree.args.foreach(arg => checked(arg)(arg, "Cannot use `unused` value in a context that is not `unused`"))
3630
tree
3731
}
3832

3933
override def transformDefDef(tree: DefDef)(implicit ctx: Context): tree.type = {
40-
checkUnusedNothing(tree)
4134
checkedValOrDefDefRHS(tree)
4235
}
4336

4437
override def transformValDef(tree: ValDef)(implicit ctx: Context): tree.type = {
45-
checkUnusedNothing(tree)
46-
if (tree.symbol.is(Unused) && tree.symbol.is(MutableOrLazy))
47-
ctx.error(tree.symbol.showKind + " cannot be unused", tree.pos)
4838
checkedValOrDefDefRHS(tree)
4939
}
5040

@@ -66,12 +56,6 @@ class UnusedChecks extends MiniPhase {
6656

6757
/* private methods */
6858

69-
/** Check that unused values are not of type Nothing */
70-
private def checkUnusedNothing(tree: Tree)(implicit ctx: Context): Unit = {
71-
if (tree.symbol.is(Unused) && tree.tpe.widen.finalResultType.isBottomType)
72-
ctx.error("unused " + tree.symbol.showKind + " cannot have type Nothing", tree.pos)
73-
}
74-
7559
/** Check that the expression is not a reference to an unused value */
7660
private def checkedValOrDefDefRHS(tree: ValOrDefDef)(implicit ctx: Context): tree.type =
7761
if (tree.symbol.is(Unused)) tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,12 @@ object Checking {
377377
fail(CannotHaveSameNameAs(sym, cls, CannotHaveSameNameAs.CannotBeOverridden))
378378
sym.setFlag(Private) // break the overriding relationship by making sym Private
379379
}
380+
checkApplicable(UnusedType, !sym.is(UnusedType))
381+
if (sym.is(Unused)) {
382+
checkApplicable(Unused, !sym.is(MutableOrLazy))
383+
if (sym.info.widen.finalResultType.isBottomType)
384+
fail("unused " + sym.showKind + " cannot have type Nothing")
385+
}
380386
}
381387

382388
/** Check the type signature of the symbol `M` defined by `tree` does not refer

0 commit comments

Comments
 (0)