Skip to content

Commit 808017c

Browse files
authored
Merge pull request #395 from scala/backport-lts-3.3-23037
Backport "Keep unused annot on params" to 3.3 LTS
2 parents c496989 + ae17e7e commit 808017c

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
@@ -194,8 +194,10 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
194194
else
195195
if sym.is(Param) then
196196
// @unused is getter/setter but we want it on ordinary method params
197-
if !sym.owner.is(Method) || sym.owner.isConstructor then
198-
sym.keepAnnotationsCarrying(thisPhase, Set(defn.ParamMetaAnnot), orNoneOf = defn.NonBeanMetaAnnots)
197+
// @param should be consulted only for fields
198+
val unusing = sym.getAnnotation(defn.UnusedAnnot)
199+
sym.keepAnnotationsCarrying(thisPhase, Set(defn.ParamMetaAnnot), orNoneOf = defn.NonBeanMetaAnnots)
200+
unusing.foreach(sym.addAnnotation)
199201
else if sym.is(ParamAccessor) then
200202
sym.keepAnnotationsCarrying(thisPhase, Set(defn.GetterMetaAnnot, defn.FieldMetaAnnot))
201203
else

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)