-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[parse] Recover better from malformed subscript decls for code-completion #13348
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
[parse] Recover better from malformed subscript decls for code-completion #13348
Conversation
@swift-ci please test |
@DougGregor any concerns about the type-checker changes or in general about subscript element type now being potentially null? |
Build failed |
Build failed |
Can we set the element type to ErrorType in the recovery path in the parser instead, so that downstream clients don't have to handle it? |
Talked to @benlangmuir in person, we're both happy with the fix now. |
The test failure is a crash in a case we used to give up earlier. We're crashing because there is no interface type on the parameter of the getter for the subscript:
But I don't see how this was going to work. In the parser, if a subscript is not inside a container type, we immediately set its interface type: if (Invalid) {
Subscript->setInterfaceType(ErrorType::get(Context));
Subscript->setInvalid();
} And the DeclChecker sees that the decl has a type, so it early-exits without setting types on the parameters of the Subscript. Then we propagate the same types onto the Decl for the accessor, which then asserts because it expects a parameter type. @slavapestov what part(s) of this chain of events are incorrect? I'm not sure how to proceed. |
…tion Code-completion of generic types expects to get a DeclContext for the subscript, so make sure we recover well enough to produce a SubscriptDecl. rdar://35619175
06703db
to
dc5888d
Compare
@swift-ci please test |
Build failed |
Build failed |
Update: I talked to Doug in person about this and he suggested we not set the interface type in the parser but let the DeclChecker do it correctly. I also took another look at how parameters are handled and discovered that while they can be null, that only should happen with closures not with functions, so instead of using null I'm setting ErrorTypeRepr on the element type to be more consistent, which is also closer to what Slava originally suggested. |
@swift-ci please test |
Code-completion of generic types expects to get a DeclContext for the
subscript, so make sure we recover well enough to produce a
SubscriptDecl.
rdar://35619175