File tree Expand file tree Collapse file tree 3 files changed +14
-10
lines changed
main/java/com/google/devtools/j2objc/translate
test/java/com/google/devtools/j2objc/translate Expand file tree Collapse file tree 3 files changed +14
-10
lines changed Original file line number Diff line number Diff line change 3939import com .google .devtools .j2objc .ast .FunctionInvocation ;
4040import com .google .devtools .j2objc .ast .IfStatement ;
4141import com .google .devtools .j2objc .ast .InfixExpression ;
42+ import com .google .devtools .j2objc .ast .InstanceofExpression ;
4243import com .google .devtools .j2objc .ast .LabeledStatement ;
4344import com .google .devtools .j2objc .ast .MethodDeclaration ;
4445import com .google .devtools .j2objc .ast .MethodInvocation ;
@@ -608,6 +609,15 @@ public boolean visit(InfixExpression node) {
608609 return true ;
609610 }
610611
612+ @ Override
613+ public boolean visit (InstanceofExpression node ) {
614+ VariableElement maybeNullVar = TreeUtil .getVariableElement (node .getLeftOperand ());
615+ if (maybeNullVar != null ) {
616+ setConditionalSafeVars (node , Collections .singleton (maybeNullVar ), EMPTY_VARS );
617+ }
618+ return true ;
619+ }
620+
611621 private boolean handleConditionalOperator (InfixExpression node , boolean logicalAnd ) {
612622 Set <VariableElement > newSafeVars = new HashSet <>();
613623 int pushCount = 0 ;
Original file line number Diff line number Diff line change @@ -635,8 +635,6 @@ public void testUnboxingMethodWithDifferentReturnType() throws IOException {
635635 + " }\n "
636636 + " }\n "
637637 + "}" , "Test" , "Test.m" );
638- assertInTranslation (
639- translation ,
640- "return [((JavaLangCharacter *) nil_chk((JavaLangCharacter *) o)) charValue];" );
638+ assertInTranslation (translation , "return [(JavaLangCharacter *) o charValue];" );
641639 }
642640}
Original file line number Diff line number Diff line change @@ -287,13 +287,9 @@ public void testIfStatementCastChkOptimization() throws IOException {
287287 " }" ,
288288 "}" ), "Test" , "Test.m" );
289289 assertNotInTranslation (translation , "cast_chk" );
290- assertInTranslation (
291- translation , "return [((JavaLangInteger *) nil_chk(((JavaLangInteger *) o))) intValue];" );
292- assertInTranslation (
293- translation , "return [((JavaLangDouble *) nil_chk(((JavaLangDouble *) o))) intValue];" );
294- assertInTranslation (
295- translation ,
296- "return [((JavaLangCharacter *) nil_chk(((JavaLangCharacter *) o))) charValue];" );
290+ assertInTranslation (translation , "return [((JavaLangInteger *) o) intValue];" );
291+ assertInTranslation (translation , "return [((JavaLangDouble *) o) intValue];" );
292+ assertInTranslation (translation , "return [((JavaLangCharacter *) o) charValue];" );
297293 }
298294
299295 public void testIfStatementCastChkNoOpt () throws IOException {
You can’t perform that action at this time.
0 commit comments