Summary: public The ivar corresponding to the property is only available in the ast when the implementation of the peroperty is available. Otherwise we add an ivar with the correct type and the default name to the tenv and use it in the getter (and later in the setter). This was not causing crashes because the generated code was swallowing the Missing_fld exception. Now it flags it. Reviewed By: akotulski Differential Revision: D2734217 fb-gh-sync-id: 21c62afmaster
parent
6d7521809b
commit
c02b3ca034
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2015 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#import <Foundation/NSObject.h>
|
||||
|
||||
@interface A : NSObject
|
||||
|
||||
@property (nonatomic) int x;
|
||||
|
||||
@end
|
||||
|
||||
@interface B : NSObject
|
||||
|
||||
@property (nonatomic) int y;
|
||||
|
||||
@end
|
||||
|
||||
@implementation A
|
||||
|
||||
@synthesize x;
|
||||
|
||||
|
||||
-(int) test {
|
||||
int* p = 0;
|
||||
self->x = 5;
|
||||
if (self.x == 5) { // If NPE is found, means that getter is using the correct ivar name x
|
||||
//rather than the default _x
|
||||
return *p;
|
||||
};
|
||||
}
|
||||
|
||||
-(int) testDefaultName {
|
||||
int* p = 0;
|
||||
B *b = [[B alloc] init];
|
||||
b.y = 5;
|
||||
if (b.y == 5) { // If NPE is found, means that getter is using default name _y that is
|
||||
// added to the tenv, so there is no Missing_fld beforehand.
|
||||
return *p;
|
||||
};
|
||||
}
|
||||
@end
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2013 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
package endtoend.objc;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static utils.matchers.ResultContainsExactly.containsExactly;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import utils.DebuggableTemporaryFolder;
|
||||
import utils.InferException;
|
||||
import utils.InferResults;
|
||||
import utils.InferRunner;
|
||||
|
||||
public class ExplicitIvarNameInGetterTest {
|
||||
|
||||
public static final String FILE =
|
||||
"infer/tests/codetoanalyze/objc/errors/property/ExplicitIvarName.m";
|
||||
|
||||
|
||||
private static ImmutableList<String> inferCmd;
|
||||
|
||||
public static final String NULL_DEREFERENCE = "NULL_DEREFERENCE";
|
||||
|
||||
@ClassRule
|
||||
public static DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder();
|
||||
|
||||
@BeforeClass
|
||||
public static void runInfer() throws InterruptedException, IOException {
|
||||
inferCmd = InferRunner.createObjCInferCommandWithMLBuckets(
|
||||
folder,
|
||||
FILE,
|
||||
"cf",
|
||||
true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInferRunsOnAtomicProperty()
|
||||
throws InterruptedException, IOException, InferException {
|
||||
InferResults inferResults = InferRunner.runInferObjC(inferCmd);
|
||||
assertThat(
|
||||
"Results should contain null dereference",
|
||||
inferResults,
|
||||
containsExactly(
|
||||
NULL_DEREFERENCE,
|
||||
FILE,
|
||||
new String[]{
|
||||
"test",
|
||||
"testDefaultName"
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue