This test will fail:
#import "GTMSenTestCase.h"
@interface Person : NSObject
@property (readonly) NSString *name;
@end
@implementation Person
- (NSString *)name { return @"Nick"; }
@end
@interface TemplateUnitTest : GTMTestCase @end
@implementation TemplateUnitTest
static BOOL called = NO;
- (Person *)get {
if (called) { STFail(nil); }
called = YES;
return [[Person new] autorelease];
}
- (void)testPropertyMakesThingGetSentTwice {
NSString *s = [[self get].name stringByAppendingString:@"foo"];
STAssertEqualObjects(@"Nickfoo", s, nil);
}
@end
If I replace the [self get].name
with [[self get] name]
, it passes. ie, Using dot-syntax, the LHS of the '.' is evaluated twice. How does this happen?