-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[TypeChecker] Fix crash with Objective C keypaths. #17497
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
We have a crash reported but do not have a test case and my attempt at creating one was unsuccessful. It seems like the issue is that we have an invalid decl that we attempt to access the interface type on, though, so hopefully this fixes the issue. I also tweaked the constraint generator to bail out when checkObjCKeyPathExpr fails. Potentially fixes: rdar://problem/40955755
@swift-ci Please smoke test |
@@ -3280,7 +3280,8 @@ namespace { | |||
if (auto keyPath = dyn_cast<KeyPathExpr>(expr)) { | |||
if (keyPath->isObjC()) { | |||
auto &cs = CG.getConstraintSystem(); | |||
(void)cs.getTypeChecker().checkObjCKeyPathExpr(cs.DC, keyPath); | |||
if (!cs.getTypeChecker().checkObjCKeyPathExpr(cs.DC, keyPath)) |
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.
Do we emit a diagnostic when this returns false?
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.
Yes, at least in the cases we already hit this in during test runs.
lib/Sema/TypeCheckExprObjC.cpp
Outdated
@@ -317,6 +317,8 @@ Optional<Type> TypeChecker::checkObjCKeyPathExpr(DeclContext *dc, | |||
// Handle property references. | |||
if (auto var = dyn_cast<VarDecl>(found)) { | |||
validateDecl(var); | |||
if (var->isInvalid() || !var->hasInterfaceType()) |
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.
Try a property with no declared type and an initial value expression that references itself via a keypath
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.
To be clear, I can get this code to be hit, but not with a nullptr interface type. Instead, we have an error type.
I'll push another commit that checks explicitly for error types and adds a test case that exercises that path.
It would be nice to understand how this was actually reaching this point with a null type, though - it's probably indicative of some bad path in decl validation.
And add a test that exercises this exit path (although it won't crash a compiler without my fixes because we do end up with ErrorType in that case, not a nullptr).
@swift-ci Please smoke test and merge |
@swift-ci Please smoke test |
We have a crash reported but do not have a test case and my attempt at
creating one was unsuccessful. It seems like the issue is that we have
an invalid decl that we attempt to access the interface type on,
though, so hopefully this fixes the issue.
I also tweaked the constraint generator to bail out when
checkObjCKeyPathExpr fails.
Potentially fixes: rdar://problem/40955755