|
1 | | -package dotty.tools.dotc |
| 1 | +package dotty.tools |
| 2 | +package dotc |
2 | 3 | package transform |
3 | 4 |
|
4 | 5 | import core._ |
@@ -193,8 +194,11 @@ object TypeTestsCasts { |
193 | 194 | tree.fun.symbol == defn.Any_typeTest || // new scheme |
194 | 195 | expr.symbol.is(Case) // old scheme |
195 | 196 |
|
196 | | - def transformIsInstanceOf(expr: Tree, testType: Type, flagUnrelated: Boolean): Tree = { |
| 197 | + def transformIsInstanceOf( |
| 198 | + expr: Tree, testType: Type, |
| 199 | + unboxedTestType: Type, flagUnrelated: Boolean): Tree = { |
197 | 200 | def testCls = effectiveClass(testType.widen) |
| 201 | + def unboxedTestCls = effectiveClass(unboxedTestType.widen) |
198 | 202 |
|
199 | 203 | def unreachable(why: => String)(using Context): Boolean = { |
200 | 204 | if (flagUnrelated) |
@@ -226,9 +230,10 @@ object TypeTestsCasts { |
226 | 230 | def check(foundCls: Symbol): Boolean = |
227 | 231 | if (!isCheckable(foundCls)) true |
228 | 232 | else if (!foundCls.derivesFrom(testCls)) { |
229 | | - val unrelated = !testCls.derivesFrom(foundCls) && ( |
230 | | - testCls.is(Final) || !testCls.is(Trait) && !foundCls.is(Trait) |
231 | | - ) |
| 233 | + val unrelated = |
| 234 | + !testCls.derivesFrom(foundCls) |
| 235 | + && !unboxedTestCls.derivesFrom(foundCls) |
| 236 | + && (testCls.is(Final) || !testCls.is(Trait) && !foundCls.is(Trait)) |
232 | 237 | if (foundCls.is(Final)) |
233 | 238 | unreachable(i"$exprType is not a subclass of $testCls") |
234 | 239 | else if (unrelated) |
@@ -265,7 +270,8 @@ object TypeTestsCasts { |
265 | 270 | case List(cls) if cls.isPrimitiveValueClass => |
266 | 271 | constant(expr, Literal(Constant(foundClsSyms.head == testCls))) |
267 | 272 | case _ => |
268 | | - transformIsInstanceOf(expr, defn.boxedType(testCls.typeRef), flagUnrelated) |
| 273 | + transformIsInstanceOf( |
| 274 | + expr, defn.boxedType(testCls.typeRef), testCls.typeRef, flagUnrelated) |
269 | 275 | else |
270 | 276 | derivedTree(expr, defn.Any_isInstanceOf, testType) |
271 | 277 | } |
@@ -342,7 +348,8 @@ object TypeTestsCasts { |
342 | 348 | case AppliedType(tref: TypeRef, _) if tref.symbol == defn.PairClass => |
343 | 349 | ref(defn.RuntimeTuple_isInstanceOfNonEmptyTuple).appliedTo(expr) |
344 | 350 | case _ => |
345 | | - transformIsInstanceOf(expr, erasure(testType), flagUnrelated) |
| 351 | + val erasedTestType = erasure(testType) |
| 352 | + transformIsInstanceOf(expr, erasedTestType, erasedTestType, flagUnrelated) |
346 | 353 | } |
347 | 354 |
|
348 | 355 | if (sym.isTypeTest) { |
|
0 commit comments