Skip to content

Commit 2177da5

Browse files
committed
Move error for unused case accessors
1 parent e755dd8 commit 2177da5

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,6 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
254254
ctx.compilationUnit.source.exists &&
255255
sym != defn.SourceFileAnnot)
256256
sym.addAnnotation(Annotation.makeSourceFile(ctx.compilationUnit.source.file.path))
257-
if (sym.is(Case)) {
258-
tree.rhs match {
259-
case rhs: Template =>
260-
for (param <- rhs.constr.vparamss.head if param.symbol.is(Unused))
261-
ctx.error("First parameter list of case classes may not contain `unused` parameters", param.pos)
262-
case _ =>
263-
}
264-
}
265257
tree
266258
}
267259
super.transform(tree)
@@ -322,8 +314,12 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
322314
}
323315

324316
private def checkNotUnused(tree: RefTree)(implicit ctx: Context): Unit = {
325-
if (tree.symbol.is(Unused) && !ctx.mode.is(Mode.Type))
326-
ctx.error(i"`unused` value $tree can only be used as unused arguments", tree.pos)
317+
if (tree.symbol.is(Unused) && !ctx.mode.is(Mode.Type)) {
318+
val msg =
319+
if (tree.symbol.is(CaseAccessor)) "First parameter list of case class may not contain `unused` parameters"
320+
else i"`unused` value $tree can only be used as unused arguments"
321+
ctx.error(msg, tree.pos)
322+
}
327323
}
328324
}
329325
}

tests/neg/unused-case-class.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
case class Foo1(unused x: Int) // error TODO add custom error message
1+
case class Foo1(unused x: Int) // error

0 commit comments

Comments
 (0)