@@ -783,7 +783,7 @@ private CodeExecutableElement createExecuteAndSpecialize() {
783
783
784
784
builder .tree (execution );
785
785
786
- if (hasFallthrough (group , genericType , originalFrameState )) {
786
+ if (group . hasFallthrough ()) {
787
787
builder .tree (createTransferToInterpreterAndInvalidate ());
788
788
builder .tree (createThrowUnsupported (builder , originalFrameState ));
789
789
}
@@ -1454,41 +1454,6 @@ private SpecializationGroup createSpecializationGroups() {
1454
1454
return SpecializationGroup .createFlat (reachableSpecializations );
1455
1455
}
1456
1456
1457
- private boolean hasFallthrough (SpecializationGroup group , TypeMirror forType , FrameState frameState ) {
1458
- for (TypeGuard guard : group .getTypeGuards ()) {
1459
- if (frameState .getValue (guard .getSignatureIndex ()) == null ) {
1460
- // not evaluated
1461
- return true ;
1462
- }
1463
- LocalVariable value = frameState .getValue (guard .getSignatureIndex ());
1464
- if (needsCastTo (value .getTypeMirror (), guard .getType ())) {
1465
- return true ;
1466
- }
1467
- }
1468
-
1469
- List <GuardExpression > guards = new ArrayList <>(group .getGuards ());
1470
- SpecializationData specialization = group .getSpecialization ();
1471
-
1472
- if (!guards .isEmpty ()) {
1473
- return true ;
1474
- }
1475
-
1476
- if (specialization != null && !specialization .getAssumptionExpressions ().isEmpty ()) {
1477
- return true ;
1478
- }
1479
-
1480
- if (specialization != null && mayBeExcluded (specialization )) {
1481
- return true ;
1482
- }
1483
-
1484
- List <SpecializationGroup > groupChildren = group .getChildren ();
1485
- if (!groupChildren .isEmpty ()) {
1486
- return hasFallthrough (groupChildren .get (groupChildren .size () - 1 ), forType , frameState );
1487
- }
1488
-
1489
- return false ;
1490
- }
1491
-
1492
1457
private CodeTree expectOrCast (TypeMirror sourceType , ExecutableTypeData targetType , CodeTree content ) {
1493
1458
if (needsUnexpectedResultException (targetType )) {
1494
1459
return expect (sourceType , targetType .getReturnType (), content );
@@ -1828,7 +1793,7 @@ private CodeTree visitSpecializationGroup(CodeTreeBuilder parent, Specialization
1828
1793
}
1829
1794
1830
1795
builder .end (ifCount );
1831
- hasFallthrough = ifCount > 0 ;
1796
+ hasFallthrough | = ifCount > 0 ;
1832
1797
1833
1798
} else if (execution .isSlowPath ()) {
1834
1799
@@ -1880,8 +1845,6 @@ private CodeTree visitSpecializationGroup(CodeTreeBuilder parent, Specialization
1880
1845
builder .end ();
1881
1846
}
1882
1847
1883
- builder .end (ifCount );
1884
-
1885
1848
} else {
1886
1849
1887
1850
List <AssumptionExpression > assumptions = specialization .getAssumptionExpressions ();
@@ -2009,6 +1972,7 @@ private CodeTree visitSpecializationGroup(CodeTreeBuilder parent, Specialization
2009
1972
if (!guards .isEmpty ()) {
2010
1973
builder .startIf ().tree (guards ).end ();
2011
1974
builder .startBlock ();
1975
+ hasFallthrough = true ;
2012
1976
}
2013
1977
2014
1978
if (!guardAssertions .isEmpty ()) {
@@ -2129,6 +2093,7 @@ private CodeTree visitSpecializationGroup(CodeTreeBuilder parent, Specialization
2129
2093
builder .tree (state .createSet (frameState , new SpecializationData []{specialization }, true , true ));
2130
2094
2131
2095
if (needsDuplicationCheck ) {
2096
+ hasFallthrough = true ;
2132
2097
if (!useSpecializationClass ) {
2133
2098
builder .startStatement ().string (duplicateFoundName , " = true" ).end ();
2134
2099
}
@@ -2155,7 +2120,7 @@ private CodeTree visitSpecializationGroup(CodeTreeBuilder parent, Specialization
2155
2120
}
2156
2121
2157
2122
builder .end (ifCount );
2158
- hasFallthrough = ifCount > 0 ;
2123
+ hasFallthrough | = ifCount > 0 ;
2159
2124
2160
2125
} else if (execution .isGuardFallback ()) {
2161
2126
@@ -2232,7 +2197,7 @@ private CodeTree visitSpecializationGroup(CodeTreeBuilder parent, Specialization
2232
2197
2233
2198
builder .end (ifCount );
2234
2199
2235
- hasFallthrough = ifCount > 0 ;
2200
+ hasFallthrough | = ifCount > 0 ;
2236
2201
2237
2202
} else {
2238
2203
throw new AssertionError ("unexpected path" );
@@ -2646,9 +2611,21 @@ private CodeTree[] createTypeCheckAndLocals(SpecializationGroup group, List<Type
2646
2611
int signatureIndex = typeGuard .getSignatureIndex ();
2647
2612
LocalVariable value = frameState .getValue (signatureIndex );
2648
2613
TypeMirror targetType = typeGuard .getType ();
2614
+
2649
2615
if (!ElementUtils .needsCastTo (value .getTypeMirror (), targetType )) {
2650
- continue ;
2616
+ List <ImplicitCastData > casts = typeSystem .lookupByTargetType (targetType );
2617
+ boolean foundImplicitSubType = false ;
2618
+ for (ImplicitCastData cast : casts ) {
2619
+ if (ElementUtils .isSubtype (cast .getSourceType (), targetType )) {
2620
+ foundImplicitSubType = true ;
2621
+ break ;
2622
+ }
2623
+ }
2624
+ if (!foundImplicitSubType ) {
2625
+ continue ;
2626
+ }
2651
2627
}
2628
+
2652
2629
NodeExecutionData execution = node .getChildExecutions ().get (signatureIndex );
2653
2630
if (!checksBuilder .isEmpty ()) {
2654
2631
checksBuilder .string (" && " );
0 commit comments