Skip to content

[CodeCompletion] Fix issue causing the completion status to not be set correctly for pattern completion #38559

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
Jul 28, 2021

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Jul 22, 2021

We weren’t setting the code completion token status correctly when parsing patterns with code completion tokens.

Because of this, in the added test case, the searchSubject gets added as a member of Foo twice - once in the first pass and once in the second pass, causing an assertion failure.

Fixes rdar://80575116 [SR-14687]

@ahoppen ahoppen requested review from rintaro and hamishknight July 22, 2021 14:52
@ahoppen
Copy link
Member Author

ahoppen commented Jul 22, 2021

@swift-ci Please smoke test

Copy link
Contributor

@hamishknight hamishknight left a comment

Choose a reason for hiding this comment

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

A little unfortunate that this is needed, but looks good to me!

@rintaro
Copy link
Member

rintaro commented Jul 23, 2021

Hmm, there's a guard not to call Handler in code completion first pass:
https://github.com/apple/swift/blob/35aa862e1d9ab38b530faefdc6a8dd21839b96cf/lib/Parse/ParseDecl.cpp#L4287-L4289

https://github.com/apple/swift/blob/35aa862e1d9ab38b530faefdc6a8dd21839b96cf/lib/Parse/ParseDecl.cpp#L4564-L4565

So if

once in the first pass and once in the second pass.

is true, there must be something wrong in DeclResult status.

@rintaro
Copy link
Member

rintaro commented Jul 23, 2021

class Foo {
   let searchSubject = Bar<String, #^COMPLETE^#
 }

Apparently, <String, #^COMPLETE^# is not parsed as a generic argument list because it's missing >. So I wonder why the let decl ends up being a completion declaration.. 🤔

@rintaro
Copy link
Member

rintaro commented Jul 23, 2021

An interesting test case is

protocol P {
  var value: Int { get }
}
struct S: P {
  let foo = val, #COMPLETE^#
}

We want to offer value: Int as an override completion. Currently it crashes in the same way.

@ahoppen ahoppen force-pushed the pr/dont-add-members-twice branch 2 times, most recently from d1deae4 to f6ef7cb Compare July 26, 2021 18:22
@ahoppen ahoppen changed the title [CodeCompletion] Avoid adding members twice - once from the first and once from the second pass [CodeCompletion] Fix issue causing the completion status to not be set correctly for pattern completion Jul 26, 2021
@ahoppen
Copy link
Member Author

ahoppen commented Jul 26, 2021

Thanks a lot, @rintaro, there was indeed a simpler fix to just set the code completion status correctly in pattern parsing. I updated the PR accordingly.

@ahoppen
Copy link
Member Author

ahoppen commented Jul 26, 2021

@swift-ci Please smoke test

…t correctly for pattern completion

We weren’t setting the code completion token status correctly when parsing patterns with code completion tokens.

Because of this, in the added test case, the `searchSubject` gets added as a member of `Foo` twice - once in the first pass and once in the second pass, causing an assertion failure.

Fixes rdar://80575116 [SR-14687]
@ahoppen ahoppen force-pushed the pr/dont-add-members-twice branch from f6ef7cb to fec7f6c Compare July 26, 2021 18:50
@ahoppen
Copy link
Member Author

ahoppen commented Jul 26, 2021

@swift-ci Please smoke test

@ahoppen
Copy link
Member Author

ahoppen commented Jul 27, 2021

@swift-ci Please smoke test macOS

1 similar comment
@ahoppen
Copy link
Member Author

ahoppen commented Jul 28, 2021

@swift-ci Please smoke test macOS

@ahoppen ahoppen merged commit 77cb4b6 into swiftlang:main Jul 28, 2021
@ahoppen ahoppen deleted the pr/dont-add-members-twice branch July 28, 2021 16:22
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