compiler does not report error when trying to call object method with [self class]

Originator:Raubtiger
Number:rdar://19410578 Date Originated:08-Jan-2015 11:01 AM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 6.1 and Xcode 6.2 (6C101); OS X 10.10.1 (14B25)
Classification:Serious Bug Reproducible:Always
 
Summary:
When calling an object method (like -(id)method) with [self class] (like [[self class] method]) the compiler does not report an error. The code will crash though.

Steps to Reproduce:
1. Open attached Xcode sample project (SelfClass.zip)
2. Build and run (should work)
3. change method +bar to -bar
4. Compile
5. Run

Expected Results:
At step 4 the compiler should show an error

Actual Results:
No error at step 4.

Version:
Xcode 6.1 and Xcode 6.2 (6C101); OS X 10.10.1 (14B25)

Here is the code from the sample project (OpenRadar only):

#import <Foundation/Foundation.h>

@interface A : NSObject
@end


@implementation A

- (NSString*) foo
{
    NSString *bar = [[self class] bar];
    return [NSString stringWithFormat:@"foo - %@", bar];
}

+ (NSString*) bar
{
    return @"bar";
}

@end

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // insert code here...
        NSLog(@"Hello, World!");

        A *a = [A new];
        NSLog(@"-foo returns '%@'", [a foo]);
    }
    return 0;
}

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!