diff --git a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala index 9134e9736079..6d5175bf17a0 100644 --- a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala +++ b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala @@ -194,8 +194,10 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase else if sym.is(Param) then // @unused is getter/setter but we want it on ordinary method params - if !sym.owner.is(Method) || sym.owner.isConstructor then - sym.keepAnnotationsCarrying(thisPhase, Set(defn.ParamMetaAnnot), orNoneOf = defn.NonBeanMetaAnnots) + // @param should be consulted only for fields + val unusing = sym.getAnnotation(defn.UnusedAnnot) + sym.keepAnnotationsCarrying(thisPhase, Set(defn.ParamMetaAnnot), orNoneOf = defn.NonBeanMetaAnnots) + unusing.foreach(sym.addAnnotation) else if sym.is(ParamAccessor) then sym.keepAnnotationsCarrying(thisPhase, Set(defn.GetterMetaAnnot, defn.FieldMetaAnnot)) else diff --git a/tests/warn/i23033.scala b/tests/warn/i23033.scala new file mode 100644 index 000000000000..6170664e05e2 --- /dev/null +++ b/tests/warn/i23033.scala @@ -0,0 +1,13 @@ +//> using options -Werror -Wunused:all + +import scala.annotation.unused +import scala.concurrent.ExecutionContext +import scala.util.NotGiven + +object Test { + given [T](using @unused ev: NotGiven[T <:< Int]): AnyRef with {} +} +object Useful: + given [T](using @unused ec: ExecutionContext): AnyRef with {} +object Syntax: + given [T] => (@unused ec: ExecutionContext) => AnyRef