Skip to content

Commit

Permalink
Check enhanced for loop expression for nil.
Browse files Browse the repository at this point in the history
	Change on 2013/10/29 by tball <tball@google.com>
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=55788639
  • Loading branch information
tomball committed Nov 1, 2013
1 parent 3962d51 commit 43a3bf4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ public boolean visit(DoStatement node) {

@Override
public boolean visit(EnhancedForStatement node) {
addNilCheck(node.getExpression(), false);
node.getExpression().accept(this);
pushScope();
node.getBody().accept(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,17 @@ public void testNilCheckAfterConditionalInfix() throws IOException {
"BOOL b2 = b || [((Test *) nil_chk(t2)) foo];",
"[((Test *) nil_chk(t2)) foo];");
}

public void testNilCheckEnhancedForExpression() throws IOException {
String translation = translateSourceFile(
"public class Test {" +
" boolean test(String target, java.util.List<String> strings) {" +
" for (String s : strings) {" +
" if (s.equals(target)) return true;" +
" }" +
" return false;" +
" }}",
"Test", "Test.m");
assertTranslation(translation, "nil_chk(strings)");
}
}

0 comments on commit 43a3bf4

Please sign in to comment.