Lines 352-363
Link Here
|
352 |
ReferenceBinding interfaceType = (ReferenceBinding) expressionType; |
352 |
ReferenceBinding interfaceType = (ReferenceBinding) expressionType; |
353 |
match = interfaceType.findSuperTypeWithSameErasure(castType); |
353 |
match = interfaceType.findSuperTypeWithSameErasure(castType); |
354 |
if (match != null) { |
354 |
if (match != null) { |
355 |
return checkUnsafeCast(scope, castType, interfaceType, match, false); |
355 |
if (use15specifics) { |
|
|
356 |
return checkUnsafeCast(scope, castType, interfaceType, match, false); |
357 |
} |
358 |
return true; |
356 |
} |
359 |
} |
357 |
tagAsNeedCheckCast(); |
360 |
tagAsNeedCheckCast(); |
358 |
match = castType.findSuperTypeWithSameErasure(interfaceType); |
361 |
match = castType.findSuperTypeWithSameErasure(interfaceType); |
359 |
if (match != null) { |
362 |
if (match != null) { |
360 |
return checkUnsafeCast(scope, castType, interfaceType, match, true); |
363 |
if (use15specifics) { |
|
|
364 |
return checkUnsafeCast(scope, castType, interfaceType, match, true); |
365 |
} |
366 |
return true; |
361 |
} |
367 |
} |
362 |
if (use15specifics) { |
368 |
if (use15specifics) { |
363 |
checkUnsafeCast(scope, castType, expressionType, null /*no match*/, true); |
369 |
checkUnsafeCast(scope, castType, expressionType, null /*no match*/, true); |
Lines 387-415
Link Here
|
387 |
tagAsUnnecessaryCast(scope, castType); |
393 |
tagAsUnnecessaryCast(scope, castType); |
388 |
return true; |
394 |
return true; |
389 |
} |
395 |
} |
390 |
if (((ReferenceBinding) castType).isFinal()) { |
396 |
// can only be a downcast |
391 |
// no subclass for castType, thus compile-time check is valid |
397 |
tagAsNeedCheckCast(); |
392 |
match = castType.findSuperTypeWithSameErasure(expressionType); |
398 |
match = castType.findSuperTypeWithSameErasure(expressionType); |
393 |
if (match == null) { |
399 |
if (match != null) { |
394 |
return false; |
400 |
if (use15specifics) { |
|
|
401 |
return checkUnsafeCast(scope, castType, expressionType, match, true); |
395 |
} |
402 |
} |
|
|
403 |
return true; |
404 |
} |
405 |
if (((ReferenceBinding) castType).isFinal()) { |
406 |
// no subclass for castType, thus compile-time check is invalid |
407 |
return false; |
396 |
} |
408 |
} |
397 |
if (use15specifics) { |
409 |
if (use15specifics) { |
|
|
410 |
checkUnsafeCast(scope, castType, expressionType, null /*no match*/, true); |
398 |
// ensure there is no collision between both interfaces: i.e. I1 extends List<String>, I2 extends List<Object> |
411 |
// ensure there is no collision between both interfaces: i.e. I1 extends List<String>, I2 extends List<Object> |
399 |
if (((ReferenceBinding)castType).hasIncompatibleSuperType((ReferenceBinding) expressionType)) { |
412 |
if (((ReferenceBinding)castType).hasIncompatibleSuperType((ReferenceBinding) expressionType)) { |
400 |
return false; |
413 |
return false; |
401 |
} |
414 |
} |
402 |
} |
415 |
} |
|
|
416 |
return true; |
403 |
} |
417 |
} |
404 |
} |
418 |
} |
405 |
tagAsNeedCheckCast(); |
|
|
406 |
return true; |
407 |
} else { |
419 |
} else { |
408 |
switch (castType.kind()) { |
420 |
switch (castType.kind()) { |
409 |
case Binding.ARRAY_TYPE : |
421 |
case Binding.ARRAY_TYPE : |
410 |
// ( ARRAY ) CLASS |
422 |
// ( ARRAY ) CLASS |
411 |
if (expressionType.id == T_JavaLangObject) { // potential runtime error |
423 |
if (expressionType.id == T_JavaLangObject) { // potential runtime error |
412 |
checkUnsafeCast(scope, castType, expressionType, expressionType, true); |
424 |
if (use15specifics) checkUnsafeCast(scope, castType, expressionType, expressionType, true); |
413 |
tagAsNeedCheckCast(); |
425 |
tagAsNeedCheckCast(); |
414 |
return true; |
426 |
return true; |
415 |
} |
427 |
} |
Lines 429-449
Link Here
|
429 |
// ( INTERFACE ) CLASS |
441 |
// ( INTERFACE ) CLASS |
430 |
ReferenceBinding refExprType = (ReferenceBinding) expressionType; |
442 |
ReferenceBinding refExprType = (ReferenceBinding) expressionType; |
431 |
match = refExprType.findSuperTypeWithSameErasure(castType); |
443 |
match = refExprType.findSuperTypeWithSameErasure(castType); |
432 |
if (refExprType.isFinal()) { |
444 |
if (match != null) { |
433 |
// unless final a subclass may implement the interface ==> no check at compile time |
445 |
if (use15specifics) { |
434 |
if (match == null) { |
|
|
435 |
return false; |
436 |
} |
437 |
return checkUnsafeCast(scope, castType, expressionType, match, false); |
438 |
} else { |
439 |
if (match != null) { |
440 |
return checkUnsafeCast(scope, castType, expressionType, match, false); |
446 |
return checkUnsafeCast(scope, castType, expressionType, match, false); |
441 |
} |
447 |
} |
|
|
448 |
return true; |
449 |
} |
450 |
// unless final a subclass may implement the interface ==> no check at compile time |
451 |
if (refExprType.isFinal()) { |
452 |
return false; |
442 |
} |
453 |
} |
443 |
tagAsNeedCheckCast(); |
454 |
tagAsNeedCheckCast(); |
444 |
match = castType.findSuperTypeWithSameErasure(expressionType); |
455 |
match = castType.findSuperTypeWithSameErasure(expressionType); |
445 |
if (match != null) { |
456 |
if (match != null) { |
446 |
return checkUnsafeCast(scope, castType, expressionType, match, true); |
457 |
if (use15specifics) { |
|
|
458 |
return checkUnsafeCast(scope, castType, expressionType, match, true); |
459 |
} |
460 |
return true; |
447 |
} |
461 |
} |
448 |
if (use15specifics) { |
462 |
if (use15specifics) { |
449 |
checkUnsafeCast(scope, castType, expressionType, null /*no match*/, true); |
463 |
checkUnsafeCast(scope, castType, expressionType, null /*no match*/, true); |
Lines 457-468
Link Here
|
457 |
match = expressionType.findSuperTypeWithSameErasure(castType); |
471 |
match = expressionType.findSuperTypeWithSameErasure(castType); |
458 |
if (match != null) { |
472 |
if (match != null) { |
459 |
if (expression != null && castType.id == T_JavaLangString) this.constant = expression.constant; // (String) cst is still a constant |
473 |
if (expression != null && castType.id == T_JavaLangString) this.constant = expression.constant; // (String) cst is still a constant |
460 |
return checkUnsafeCast(scope, castType, expressionType, match, false); |
474 |
if (use15specifics) { |
|
|
475 |
return checkUnsafeCast(scope, castType, expressionType, match, false); |
476 |
} |
477 |
return true; |
461 |
} |
478 |
} |
462 |
match = castType.findSuperTypeWithSameErasure(expressionType); |
479 |
match = castType.findSuperTypeWithSameErasure(expressionType); |
463 |
if (match != null) { |
480 |
if (match != null) { |
464 |
tagAsNeedCheckCast(); |
481 |
tagAsNeedCheckCast(); |
465 |
return checkUnsafeCast(scope, castType, expressionType, match, true); |
482 |
if (use15specifics) { |
|
|
483 |
return checkUnsafeCast(scope, castType, expressionType, match, true); |
484 |
} |
485 |
return true; |
466 |
} |
486 |
} |
467 |
return false; |
487 |
return false; |
468 |
} |
488 |
} |