@selector() disallows legal selector names if they aren't valid method names
| Originator: | chaos42 | ||
| Number: | rdar://10452161 | Date Originated: | 11/15/11 |
| Status: | Closed | Resolved: | Behaves Correctly |
| Product: | Developer Tools | Product Version: | 4.2/4C199 LLVM 3.0 |
| Classification: | Other bug | Reproducible: | Always |
Summary: the argument to the @selector keyword in Objective-C is checked for method name validity, not selector name validity; selectors with punctuation, spaces, or a final non-argument part give a compiler error. It seems acceptable to limit punctuation (since the symbol cannot be escaped in any way), but disallowing spaces and a non-argument final part is excessive. The runtime allows selector names like "hi+ :foobar:baz" and "foobar:baz", though the compiler only allows "foobar:baz:" or "foobar" or "foobar:"
Steps to Reproduce:
in Foo.m:
#import <objc/runtime.h>
void doSomething(id self, SEL _cmd, NSString *param);
@implementation Foo
...
- (void)doHorribleThingsToTheRuntime:(NSString *)str
{
SEL sele = @selector(foobar:baz);
class_addMethod([Foo class], sele, (IMP)doSomething, "v@:@");
[self performSelector:sele withObject:str];
}
@end
void doSomething(id self, SEL _cmd, NSString *param)
{
NSLog(@"hello, %@", param);
}
Expected Results:
This should compile, run, and print hello... While the compiler limits what method names are legal, there is no such limitation on selector names. The compiler should respect that, and only generate a(n optional) warning "'foobar:baz' is a valid selector, but not a valid method name"
Actual Results:
Compile error in @selector: "expected :" at end of baz
Regression:
Unknown
Notes:
Workaround: Use SEL sele = NSSelectorFromString(@"foobar:baz"); instead.
Other notes: this bug report is slightly tongue-in-cheek, but only slightly. Seriously, it'd be cool if we could have foobar:baz as a valid method name too.
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!