Why does using dot syntax cause LHS of this statement twice?

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 replaced [self get].namewith [[self get] name], it will pass. those. using dot syntax, LHS "." evaluated twice. How did this happen?

+3
source share
2 answers

The public acceptance that you use point syntax in Objective-C is likely to make you purists burn at the stake; -)

This seems to be a mistake in this particular scenario, as the thread says this is probably some preprocessing magic that extends it incorrectly.

+2
source

​​ gcc-4.2.

+2

Source: https://habr.com/ru/post/1705451/


All Articles