-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comparison predicate cannot refer to ComparisonResult enum #318
Comments
Thanks for bringing this up! This is a limitation of We've also thought about whether we could strictly allow trivial enum cases as a special case within the predicate since their value can't change between predicate evaluations unlike a static property. However, since macros only have syntactic information and not type information, there's unfortunately no way for us to differentiate between a trivial enum case and a static property. So in order to avoid unexpected behavior of static properties (for example, something like Lastly we also looked at whether we can improve the diagnostic here and/or even make a fix it to do this capturing for you. However, again since the macro doesn't have type information, given something like If you have any suggestions, I'm definitely open to ideas if you think of anything clever we can do here! But in the meantime, I think improving this scenario requires changes to the language to provide type information to macros and/or allow keypaths to static properties/enum cases. |
@jmschonfeld Thanks for the explanation. The only suggestion I can think of is that since the most common comparison will be checking if the strings compare equal, |
Yeah, I think I'd agree with you that adding |
Given the following predicate:
Compiler complains that:
Member access without an explicit base is not allowed in this predicate
.So let's change it to an explicit base:
Compiler then complains that
Key path cannot refer to enum case 'orderedSame'
.Macro expansion shows that it's now trying to build a key path expression instead of using the enum value:
A workaround is to put the enum in a variable:
Using Swift from Xcode 15.0 (15A240d).
The text was updated successfully, but these errors were encountered: