You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the following snippet, the obj identifiers in statements beginning with the composite literal obj{} are not resolved to the obj declaration.
type obj struct {}
func _() {
obj{}
obj{}.run()
}
The reason for this is that, while in the middle of parsing, LHS logic is pretty tricky to get right. Specifically, it's non-trivial to differentiate this case of a composite literal from, for example, the ok { in if _, ok := m[k]; ok {....
See also #45104: this is easy to fix when post-processing the AST, but it's nearly impossible to match the broken behavior (because it relates to source layout rather than syntax).
Filing as a separate issue as I'm going to fix it prior to #45104, so that I can match behavior exactly with the new resolution logic.
It might be easier to reproduce this bug in the new code than trying to fix the old code. Than you can still do exact behavior matching, and afterwards "fix the bug".
It might be easier to reproduce this bug in the new code than trying to fix the old code.
I have a fix for the old code. Reproducing in the new code would actually be quite tricky, because once parsed into a tree it's difficult to know if the CompositeLit you're looking at is at the start of an ExprStmt (this is what I meant above by "it relates to source layout rather than syntax").
Add new tests for object resolution driven by source files with
declarations and uses marked via special comments. This made it easier
to add test coverage while refactoring object resolution for #45104.
Tests are added to a new resolver_test.go file. In a subsequent CL the
resolver.go file will be added, making this choice of file name more
sensible.
For #45104
For #45136
For #45160
Change-Id: I240fccc0de95aa8f2d03e39c77146d4c61f1ef9e
Reviewed-on: https://go-review.googlesource.com/c/go/+/304450
Trust: Robert Findley <rfindley@google.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
In the following snippet, the
obj
identifiers in statements beginning with the composite literalobj{}
are not resolved to theobj
declaration.The reason for this is that, while in the middle of parsing, LHS logic is pretty tricky to get right. Specifically, it's non-trivial to differentiate this case of a composite literal from, for example, the
ok {
inif _, ok := m[k]; ok {...
.See also #45104: this is easy to fix when post-processing the AST, but it's nearly impossible to match the broken behavior (because it relates to source layout rather than syntax).
Filing as a separate issue as I'm going to fix it prior to #45104, so that I can match behavior exactly with the new resolution logic.
CC @griesemer
The text was updated successfully, but these errors were encountered: