Skip to content

[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

Merged
merged 5 commits into from
Dec 3, 2019

Conversation

hamishknight
Copy link
Contributor

Start resolving callees for an implicit call to callAsFunction by adding a case for it in getCalleeLocator, 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 of finishApply's transforms to it, which handles things like IUO unwraps.

Resolves SR-11386, SR-11778, SR-11829, and SR-11881.

@hamishknight
Copy link
Contributor Author

@swift-ci please test

Copy link
Contributor

@xedin xedin left a 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.
Copy link
Contributor

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.

@swiftlang swiftlang deleted a comment from swift-ci Dec 2, 2019
@hamishknight
Copy link
Contributor Author

@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.
@hamishknight
Copy link
Contributor Author

Rebased to resolve a merge conflict

@swift-ci please smoke test and merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants