Skip to content

[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

Merged
merged 1 commit into from
Dec 13, 2017

Conversation

benlangmuir
Copy link
Contributor

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

@benlangmuir
Copy link
Contributor Author

@swift-ci please test

@benlangmuir
Copy link
Contributor Author

@DougGregor any concerns about the type-checker changes or in general about subscript element type now being potentially null?

@swift-ci
Copy link
Contributor

swift-ci commented Dec 8, 2017

Build failed
Swift Test Linux Platform
Git Sha - 06703dbd80ef8419b8ce5a741cabf6ee7b932d6b

@swift-ci
Copy link
Contributor

swift-ci commented Dec 8, 2017

Build failed
Swift Test OS X Platform
Git Sha - 06703dbd80ef8419b8ce5a741cabf6ee7b932d6b

@slavapestov
Copy link
Contributor

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?

@slavapestov
Copy link
Contributor

Talked to @benlangmuir in person, we're both happy with the fix now.

@benlangmuir
Copy link
Contributor Author

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:

frame #4: 0x0000000102a25878 swiftc`swift::ValueDecl::getInterfaceType(this=0x0000000113847f80) const at Decl.cpp:1923
frame #5: 0x0000000102bfdca1 swiftc`swift::ParameterList::getInterfaceType(this=0x0000000113848018, C=0x0000000114009a00) const at Parameter.cpp:147
frame #6: 0x0000000102249ef1 swiftc`swift::TypeChecker::configureInterfaceType(this=0x00007ffeefbf7c78, func=0x0000000113848040, sig=0x0000000113849570) at TypeCheckGeneric.cpp:910
frame #7: 0x000000010220230e swiftc`(anonymous namespace)::DeclChecker::visitFuncDecl(this=0x00007ffeefbf70f8, FD=0x0000000113848040) at TypeCheckDecl.cpp:5291

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

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 06703dbd80ef8419b8ce5a741cabf6ee7b932d6b

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 06703dbd80ef8419b8ce5a741cabf6ee7b932d6b

@benlangmuir
Copy link
Contributor Author

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.

@benlangmuir
Copy link
Contributor Author

@swift-ci please test

@benlangmuir benlangmuir merged commit 68a4545 into swiftlang:master Dec 13, 2017
@benlangmuir benlangmuir deleted the cc-generic-subscript branch December 13, 2017 23:45
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.

3 participants