@@ -5,7 +5,7 @@ import dotty.tools.dotc.util.Positions._
5
5
import TreeTransforms .{MiniPhaseTransform , TransformerInfo }
6
6
import core ._
7
7
import Contexts .Context , Types ._ , Constants ._ , Decorators ._ , Symbols ._
8
- import TypeUtils ._ , TypeErasure ._ , Flags ._
8
+ import TypeUtils ._ , TypeErasure ._ , Flags ._ , TypeApplications . _
9
9
import reporting .diagnostic .messages ._
10
10
11
11
/** Implements partial evaluation of `sc.isInstanceOf[Sel]` according to:
@@ -128,6 +128,25 @@ class IsInstanceOfEvaluator extends MiniPhaseTransform { thisTransformer =>
128
128
129
129
val selClassNonFinal = selClass && ! (selector.typeSymbol is Final )
130
130
val selFinalClass = selClass && (selector.typeSymbol is Final )
131
+ val selTypeParam = tree.args.head.tpe.widen match {
132
+ case AppliedType (tycon, args) =>
133
+ ctx.uncheckedWarning(
134
+ ErasedType (hl """ |Since type parameters are erased, you should not match on them in
135
+ | ${" match" } expressions. """ ),
136
+ tree.pos
137
+ )
138
+ true
139
+ case x if tree.args.head.symbol is TypeParam =>
140
+ ctx.uncheckedWarning(
141
+ ErasedType (
142
+ hl """ |` ${tree.args.head.tpe}` will be erased to ` ${selector}`. Which means that the specified
143
+ |behavior could be different during runtime. """
144
+ ),
145
+ tree.pos
146
+ )
147
+ true
148
+ case _ => false
149
+ }
131
150
132
151
// Cases ---------------------------------
133
152
val valueClassesOrAny =
@@ -149,11 +168,8 @@ class IsInstanceOfEvaluator extends MiniPhaseTransform { thisTransformer =>
149
168
150
169
val inMatch = s.qualifier.symbol is Case
151
170
152
- if (valueClassesOrAny) {
153
- if ((selector eq defn.ObjectType ))
154
- ctx.uncheckedWarning(ErasedType (), tree.pos)
155
- tree
156
- } else if (knownStatically)
171
+ if (selTypeParam || valueClassesOrAny) tree
172
+ else if (knownStatically)
157
173
handleStaticallyKnown(s, scrutinee, selector, inMatch, tree.pos)
158
174
else if (falseIfUnrelated && scrutinee <:< selector)
159
175
// scrutinee is a subtype of the selector, safe to rewrite
0 commit comments