-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AST] getParameterAt
should check index before retrieving it
#62146
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
`getParameterAt` needs to be more defensive about the input because caller cannot always perform all the checks upfront. Resolves: rdar://102085039
@swift-ci please smoke test |
I looked at the test case in a debugger and I think the caller is calling getParameterAt() with a parameter index of 0 when in fact it's looking at the self parameter. So you have a function type Can we detect this case there instead of adding this defensive check? Otherwise, if the function does in fact have 1 parameter, getParameterAt() will succeed, but it might trigger incorrect behavior because it's looking at 'self' and it thinks it's looking at the first actual parameter. |
I see we compute the callee as follows: ValueDecl *callee = nullptr;
bool appliedSelf = false;
// Resolve the callee for the application.
auto *calleeLocator = cs.getCalleeLocator(loc);
if (auto overload = cs.findSelectedOverloadFor(calleeLocator)) {
callee = overload->choice.getDeclOrNull();
appliedSelf = hasAppliedSelf(cs, overload->choice);
} Maybe |
@slavapestov I don't think so, it's crashing in simplifyApplicableFnConstraint which has an applied reference, it tries to fetch parameter |
It's calling
So it thinks there's at least one parameter in the call. Here are the two function types:
|
I guess |
What if you change shouldOpenExistentialCallArgument() to look into the ParameterListInfo instead of getting the ParameterList from the callee directly? It looks like we already have to handle the same situation with default arguments (imagine the first formal argument is defaulted, but we're matching the self parameter). Opening an existential should similarly consult the ParameterListInfo. It looks like the ParameterListInfo::ParameterListInfo() constructor already has the right logic to detect if we're matching the |
I can look into changing |
@swift-ci please smoke test Linux platform |
@swift-ci please smoke test macOS platform |
…non-null parameter
@swift-ci please test |
getParameterAt
needs to be more defensive about the inputbecause caller cannot always perform all the checks upfront.
Resolves: rdar://102085039