-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[CS] A couple of fixes for implicit callAsFunction #28519
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
Conversation
@swift-ci please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
auto memberLoc = getConstraintLocator( | ||
outerLocator.withPathElement(ConstraintLocator::Member)); | ||
// Add a `callAsFunction` member constraint, binding the member type to a | ||
// type variable. | ||
auto memberTy = createTypeVariable(memberLoc, /*options=*/0); | ||
// TODO: Revisit this if `static func callAsFunction` is to be supported. | ||
// Static member constraint requires `FunctionRefKind::DoubleApply`. | ||
// TODO: Use a custom locator element to identify this member constraint | ||
// instead of just pointing to the function expr. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this, something that I mentioned in the original PR for this feature as would be useful.
22b7ed0
to
ed11139
Compare
@swift-ci please test |
This checks whether a type supports being called via callAsFunction. A request is used in order to cache the result of this query.
Add a case to getCalleeLocator to return the appropriate locator for a call to an implicit callAsFunction member reference. Resolves SR-11386 & SR-11778.
Previously this hit an assertion in CSApply. While we could technically make it work, it's probably best not to allow it. Resolves SR-11829.
Rather than coercing the call arguments ourselves, just build the finished member reference for the callAsFunction method, and let finishApply do the rest. This allows us to deal with transformations such as IUO unwraps. Resolves SR-11881.
We still want the constraint system to try looking up a callAsFunction method even if it's inaccessible, as we'll be able to record a fix and emit a suitable diagnostic.
ed11139
to
2d7a088
Compare
Rebased to resolve a merge conflict @swift-ci please smoke test and merge |
Start resolving callees for an implicit call to
callAsFunction
by adding a case for it ingetCalleeLocator
, which allows it to be used with default arguments and diagnosed with things like requirement failures.In addition, prevent callables from being used with
AnyObject
lookup, previously this hit an assert in CSApply, now we'll reject it with an error.Finally, tweak the CSApply logic for
callAsFunction
such that we apply all offinishApply
's transforms to it, which handles things like IUO unwraps.Resolves SR-11386, SR-11778, SR-11829, and SR-11881.