Skip to content

Commit 58e7acd

Browse files
committed
Keep unused annot on params
1 parent 02306bb commit 58e7acd

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,10 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
247247
if sym.is(Param) then
248248
registerIfUnrolledParam(sym)
249249
// @unused is getter/setter but we want it on ordinary method params
250-
if !sym.owner.is(Method) || sym.owner.isConstructor then
251-
sym.keepAnnotationsCarrying(thisPhase, Set(defn.ParamMetaAnnot), orNoneOf = defn.NonBeanMetaAnnots)
250+
// @param should be consulted only for fields
251+
val unusing = sym.getAnnotation(defn.UnusedAnnot)
252+
sym.keepAnnotationsCarrying(thisPhase, Set(defn.ParamMetaAnnot), orNoneOf = defn.NonBeanMetaAnnots)
253+
unusing.foreach(sym.addAnnotation)
252254
else if sym.is(ParamAccessor) then
253255
// @publicInBinary is not a meta-annotation and therefore not kept by `keepAnnotationsCarrying`
254256
val publicInBinaryAnnotOpt = sym.getAnnotation(defn.PublicInBinaryAnnot)

tests/warn/i23033.scala

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//> using options -Werror -Wunused:all
2+
3+
import scala.annotation.unused
4+
import scala.concurrent.ExecutionContext
5+
import scala.util.NotGiven
6+
7+
object Test {
8+
given [T](using @unused ev: NotGiven[T <:< Int]): AnyRef with {}
9+
}
10+
object Useful:
11+
given [T](using @unused ec: ExecutionContext): AnyRef with {}
12+
object Syntax:
13+
given [T] => (@unused ec: ExecutionContext) => AnyRef

0 commit comments

Comments
 (0)