@@ -135,30 +135,32 @@ class IsInstanceOfEvaluator extends MiniPhaseTransform { thisTransformer =>
135
135
val selFinalClass = selClass && (selector.typeSymbol is Final )
136
136
137
137
/** Check if the selector's potential type parameters will be erased, and if so warn */
138
- val selTypeParam = tree.args.head.tpe.widen match {
139
- case tp @ AppliedType (tycon, args ) =>
140
- // If the type is Array[X] where x extends AnyVal, this shouldn't yield a warning:
141
- val illegalComparison = ! (tp.isRef(defn. ArrayClass ) && {
142
- args.head.derivesFrom (defn.AnyValClass ) ||
143
- args.head .isRef(defn.AnyClass )
144
- } )
145
-
146
- if (illegalComparison ) ctx.uncheckedWarning(
138
+ val selTypeParam = tree.args.head.tpe.widen match {
139
+ case tp @ AppliedType (_, arg :: _ ) =>
140
+ // If the type is ` Array[X]` where `X` extends AnyVal or `X =:=
141
+ // Any`, this shouldn't yield a warning:
142
+ val isArray = tp.isRef (defn.ArrayClass )
143
+ val unerased = arg.derivesFrom(defn. AnyValClass ) || arg .isRef(defn.AnyClass )
144
+ val hasAnnot = arg.hasAnnotation(defn. UncheckedAnnot )
145
+
146
+ if (! hasAnnot && ! (isArray && unerased) ) ctx.uncheckedWarning(
147
147
ErasedType (hl """ |Since type parameters are erased, you should not match on them in
148
148
| ${" match" } expressions. """ ),
149
149
tree.pos
150
150
)
151
151
true
152
- case x if tree.args.head.symbol is TypeParam =>
153
- ctx.uncheckedWarning(
154
- ErasedType (
155
- hl """ |` ${tree.args.head.tpe}` will be erased to ` ${selector}`. Which means that the specified
156
- |behavior could be different during runtime. """
157
- ),
158
- tree.pos
159
- )
160
- true
161
- case _ => false
152
+ case _ =>
153
+ if (tree.args.head.symbol.is(TypeParam )) {
154
+ ctx.uncheckedWarning(
155
+ ErasedType (
156
+ hl """ |` ${tree.args.head.tpe}` will be erased to ` ${selector}`. Which means that the specified
157
+ |behavior could be different during runtime. """
158
+ ),
159
+ tree.pos
160
+ )
161
+ true
162
+ }
163
+ else false
162
164
}
163
165
164
166
// Cases ---------------------------------
0 commit comments