Skip to content

[CodeCompletion] Fix crash when completing in arguments of unresolved pattern inside closure #74083

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,11 @@ ConstraintLocator *ConstraintSystem::getCalleeLocator(
auto *fnExpr = applyExpr->getFn();

// Handle special cases for applies of non-function types.
if (auto *loc = getSpecialFnCalleeLoc(getType(fnExpr)))
return loc;
if (hasType(fnExpr)) {
if (auto *loc = getSpecialFnCalleeLoc(getType(fnExpr))) {
Comment on lines +704 to +705
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem right, getType is a function being passed into getCalleeLocator whereas hasType is the ConstraintSystem member; you'd need to plumb through a separate hasType function. That being said I'm curious why the type wouldn't be set here 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahoppen I dug into this a bit and discovered it's because we're re-creating the ExprPattern along different solver paths, put up #74387 to fix that which should mean we don't have to do this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! ⭐

return loc;
}
}

// Otherwise fall through and look for locators anchored on the function
// expr. For CallExprs, this can look through things like parens and
Expand Down
10 changes: 10 additions & 0 deletions validation-test/IDE/crashers_2_fixed/rdar128661960.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %batch-code-completion

func takeClosure(closure: () -> Bool) {}

func test(someLocal: Int) {
takeClosure {
if case .begin(#^COMPLETE^#)
}
}
// COMPLETE: someLocal