Navigation Menu

Skip to content
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

x/tools/gopls: inconsistent semantic token types for function #57469

Open
rink-grey opened this issue Dec 27, 2022 · 3 comments
Open

x/tools/gopls: inconsistent semantic token types for function #57469

rink-grey opened this issue Dec 27, 2022 · 3 comments
Labels
gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.

Comments

@rink-grey
Copy link

As example, a function has 3 function type parameter: fn1, fn2, fns.
fn1 is defined by normal function type.
fn2 is defined by an alias type for function.
fns is defined by variable number of arguments for an alias function type.
iShot_2022-12-27_10 34 49
it check "fn1" as function, that is correct.
iShot_2022-12-27_10 35 10
it check "fn2" as variable but not function.
iShot_2022-12-27_10 35 37
it check the element of "fns" as normal variable but not function.
iShot_2022-12-27_10 35 55
So there is inconsistent.

@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Dec 27, 2022
@gopherbot gopherbot added this to the Unreleased milestone Dec 27, 2022
@findleyr
Copy link
Contributor

CC @pjweinb

@findleyr findleyr added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 27, 2022
@pjweinb
Copy link

pjweinb commented Dec 27, 2022

In
package whatever type B func() type C = func() func Run(a func(), b B, c C, bb ...B) { a() // a is called a function b() // b is called a parameter, but it looks like a function c() // c is called a function for _, f := range bb { f() // f is called a variable, but it looks like a function } }
bi is called a parameter, even though it is used like a function, because its type is B. It can be used as a function because its core type is func(), a function type. The Go type checker identifies a and c as functions, and b as an identifier.

So the question is what 'semantic' in 'semanticToken' means. Here it could mean 'used like a function so call it a function' or it could mean whatever the Go type checker thinks [which for b, is that it is an identifier that was a parameter, and for bb, that it is a variable]

I'm inclined to leave it the way it is. The user can see (even without semantic tokens) that these identifiers are all being used to call. The semantic tokens give some information about the types: b and c have different types, even though their underlying types are both func().

@suzmue suzmue modified the milestones: Unreleased, gopls/unplanned Dec 28, 2022
@rink-grey
Copy link
Author

By @pjweinb talk, I think the main point is "a function type-alias is not identified as function by Go type checker". So it looks like the issue is not about semantic token.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants