Overloaded functions don't work properly with enums (in Objective-C)
| Originator: | arkadiusz.holko | ||
| Number: | rdar://20990819 | Date Originated: | 17-May-2015 |
| Status: | Behaves correctly | Resolved: | 21-May-2015 |
| Product: | Developer Tools | Product Version: | |
| Classification: | Reproducible: | Always |
Summary:
Let's say we have two enums and an overloaded function:
typedef NS_ENUM(NSUInteger, MyEnum) {
MyEnum1,
MyEnum2,
};
typedef NS_ENUM(NSUInteger, YourEnum) {
YourEnum1,
YourEnum2,
};
__attribute__((overloadable)) void test(MyEnum value)
{
NSLog(@"MyEnum");
}
__attribute__((overloadable)) void test(YourEnum value)
{
NSLog(@"YourEnum");
}
If we try the function in the following way:
test(MyEnum1);
we get a compile-time error: Call to 'test' is ambiguous
What works is:
1. Casting: test((MyEnum)MyEnum1);
or
2. Assigning an enum's member to variable first:
MyEnum x = MyEnum1;
test(x);
Steps to Reproduce:
Expected Results:
We shouldn't have to cast or use an intermediary variable to hint the compiler about the type of enum's member.
Actual Results:
We get a compile-time error.
Version:
Xcode 6.3.1
Real-world example that could benefit from this bug getting fix: https://github.com/fastred/ReflectableEnum
Resolved because it's the expected behavior.
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!