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

go/parser: uses of function type params are not resolved in the signature #45221

Open
findleyr opened this issue Mar 24, 2021 · 3 comments
Open

go/parser: uses of function type params are not resolved in the signature #45221

findleyr opened this issue Mar 24, 2021 · 3 comments
Assignees
Labels
Milestone

Comments

@findleyr
Copy link
Contributor

@findleyr findleyr commented Mar 24, 2021

go/parser object resolution correctly resolves type parameters within type declarations, but not within function declarations. For example, none of the uses of T in the below snippet are resolved (correction: the T in var t T is resolved, but not the Ts in the signature):

func Add[T Addable](l, r T) T {
        var t T
        return l + r + t
}

This is minor, but we should probably fix it. Will do as part of #45104.

CC @griesemer

@gopherbot
Copy link

@gopherbot gopherbot commented Mar 25, 2021

Change https://golang.org/cl/304456 mentions this issue: go/parser: move type params in scope for the function signature

@gopherbot
Copy link

@gopherbot gopherbot commented Mar 25, 2021

Change https://golang.org/cl/304453 mentions this issue: go/parser: add resolution tests for type params

@findleyr findleyr changed the title go/parser: identifiers referring to function type param are not resolved go/parser: uses of function type params are not resolved in the signature Mar 25, 2021
@cagedmantis cagedmantis added this to the Backlog milestone Mar 29, 2021
@cagedmantis
Copy link
Contributor

@cagedmantis cagedmantis commented Mar 29, 2021

/cc @@griesemer

gopherbot pushed a commit that referenced this issue Mar 31, 2021
For #45104
For #45221

Change-Id: I8966555f4e8844d5b6766d00d48f7a81868ccf40
Reviewed-on: https://go-review.googlesource.com/c/go/+/304453
Trust: Robert Findley <rfindley@google.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
@findleyr findleyr self-assigned this Apr 3, 2021
gopherbot pushed a commit that referenced this issue Apr 16, 2021
Type parameter resolution is a bit tricky: type parameters are in the
function scope, but unlike ordinary parameters may reference eachother.
When resolving the function scope, we must be careful about the order in
which objects are resolved and declared.

Using ordering allows us to avoid passing around temporary scopes for
field declarations.

Add a bunch of tests for this behavior, and skip "_" in resolution tests
as it just adds noise.

For #45221

Change-Id: Id080cddce3fd76396bf86ba5aba856aedf64a458
Reviewed-on: https://go-review.googlesource.com/c/go/+/304456
Trust: Robert Findley <rfindley@google.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
@findleyr findleyr modified the milestones: Backlog, Go1.18 Apr 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants