multiple methods named 'reason' found when importing XCTest/XCTest.h
| Originator: | jonwall | ||
| Number: | rdar://15263662 | Date Originated: | 10/18/2013 |
| Status: | Closed | Resolved: | Fixed in SDK 8 |
| Product: | Developer Tools | Product Version: | 5.0 |
| Classification: | Reproducible: | Always |
XCTestAssertionsImpl.h includes a bunch of @catch blocks that look like:
@catch (id exception) { \
_XCTRegisterFailure(_XCTFailureDescription(_XCTAssertion_False, 1, @#expression, [exception reason]),format); \
}\
Because exception is typed as id, #import'ing another header with a method named "reason" can cause this compilation error.
Steps to reproduce:
// xctest.m
#import <Foundation/Foundation.h>
#import <XCTest/XCTest.h>
@interface MyObject : NSObject
@property(nonatomic, assign) NSInteger reason;
@end
@implementation MyObject
@end
@interface MyTest : XCTestCase
@end
@implementation MyTest
- (void)testFoo {
id foo = nil;
XCTAssertNil(foo, @"foo should be nil");
}
@end
int main() {
}
xctest.m:18:3: warning: multiple methods named 'reason' found
XCTAssertNil(foo, @"foo should be nil");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/XCTest.framework/Headers/XCTestAssertions.h:47:5: note: expanded from macro 'XCTAssertNil'
_XCTPrimitiveAssertNil(a1, ## format)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/XCTest.framework/Headers/XCTestAssertionsImpl.h:94:80: note: expanded from macro '_XCTPrimitiveAssertNil'
_XCTRegisterFailure(_XCTFailureDescription(_XCTAssertion_Nil, 1, @#a1, [exception reason]),format); \
^~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/XCTest.framework/Headers/XCTestAssertionsImpl.h:70:91: note: expanded from macro '_XCTFailureDescription'
[NSString stringWithFormat:_XCTFailureFormat(assertion_type, uncaught_exception), @"" format]; \
^
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/XCTest.framework/Headers/XCTestAssertionsImpl.h:39:55: note: expanded from macro '_XCTRegisterFailure'
_XCTFailureHandler(self, YES, __FILE__, __LINE__, condition, @"" format); \
^
/System/Library/Frameworks/Foundation.framework/Headers/NSException.h:50:1: note: using
- (NSString *)reason;
^~~~~~~~~~~~~~~~~~~~~
xctest.m:6:40: note: also found
@property(nonatomic, assign) NSInteger reason;
^~~~~~
1 warning generated.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
Duplicate of 15133548 (Open)