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