-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[IDE] Fix name range of wildcard declarations #38085
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
let = 2 | ||
let : Int = 4 | ||
|
||
let x: (String) -> Void = { (: String) in } | ||
|
||
// RUN: %sourcekitd-test -req=collect-var-type %s -- %s | %FileCheck %s | ||
// CHECK: <VariableTypes> | ||
// CHECK-NEXT: (4:5, 4:6): (String) -> Void (explicit type: 1) | ||
// CHECK-NEXT: </VariableTypes> | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think this doesn’t work if the identifier starts with an underscore. E.g.
let _foo = 2
. If it does work, I think it would be worth adding a test case for it.I also don’t understand yet why this should be necessary. If the identifier is empty, then
DeclBaseName::userFacingName()
should return a_
, which has a length of 1. 🤔https://github.com/apple/swift/blob/7ccc1b054a607881978b8efa0d7042d8bcd3d63f/include/swift/AST/Identifier.h#L339
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.
If we have something like
_x
,hasName()
returns true, so it should work. The reason why this is necessary for_
is because it doesn't go down that branch if the identifier is empty, becausehasName()
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.
Perhaps we could drop the
hasName()
-check completely sinceuserFacingName()
returns the right thing in any case?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.
One thing to also consider is invalid declarations like
let = 1
orstruct {}
(not relevant for your implementation but for other users ofSemaAnnotator
), which also don’t have a name and whose name isn’t_
either.Just an idea if the logic starts to get too complicated here: You could also check for the standard straightforward cases here (no backticks, name not empty) and if that doesn’t match, use
Lexer::getTokenAtLocation
to look the actual source code up. The downside is thatLexer::getTokenAtLocation
needs to set up aLexer
instance, which is slower (although it’s not really slow either and I think we’re doing it in a variety of places).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.
Hm yes, dropping
hasName()
also seems to causetest/IDE/annotation.swift
to fail as the annotator now reports things likeinstead of
I think the standard straightforward cases as well as the backtick and
_
case should be handled correctly with the PR implementation right now, though using a lexer might be a bit cleaner than looking up the source code directly.