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: panic during object resolution: identifier already declared #64534
Comments
I think the problem is There's case that we call with |
Thanks @cuonglm. That sounds likely. I can't look into this further now, but I will note that based on the rate of internal reports, it must be possible to reproduce this panic without the invalid utf-8 produced by fuzzing. |
Here's the token stream for the TypeParams portion:
and the corresponding AST:
Notice there are two unnamed Fields of type The reason for the second field is that the parseParameterList loop over fields creates a Field (name=A, type=nil) then another with (name="" type=B), then tries to distribute the type of B across the preceding typeless fields (A). |
I fail to see how this is a release blocker. First of all, features related to object resolution by the parser have been deprecated. Second, object resolution should arguably not happen when there are (hard) syntactic errors; and there are many here (consider the trace output). Third, this is a really esoteric piece of code. Shouldn't we just turn off object resolution by default? |
For the reference, this is the syntax AST for the program package p; func _[A\x9d(B](){}
The difference is not due to the different meaning of Created with (syntax) test case, with tracing enabled: func TestIssue64534(t *testing.T) {
f, _ := Parse(nil, strings.NewReader("package p; func _[A\x9d(B](){}"), func(error) {}, nil, 0)
Fdump(os.Stdout, f)
} |
It is a new regression and a panic, so I understand why Rob added the label. And it's also not that esoteric: any character that isn't a valid token will trigger the problem, such as
Deprecated or not, and as appealing as it might be, we can't just drop syntax resolution. Unfortunately gopls must run the parser and type checker on inputs in all kinds of half-baked edit states that most users wouldn't dream of exposing to the compiler. I don't think this bug should be hard to fix, now that we understand it. |
@griesemer I marked this as a release blocker before I fully understood the nature of the problem. But it does seem concerning that the parser is producing invalid ASTs (reusing subtrees). Furthermore, while syntax resolution may be deprecated, analysis drivers must still use it as there are several existing analyzers that rely on it (and in any case, it is part of the go/analysis contract). We went from hardly getting any internal crash reports over the past 6 months, to getting several a week. In the grand scheme of things, this crash rate may be acceptable (if it only occurs for invalid code, as seems to be the case), but it does seem worth fixing sooner rather than later. We can remove the release blocker label, but keep this in the 1.22 milestone. Perhaps mark it ok-after-rc1? I can't fix it this week, but would be happy to fix it early next week. |
I'll have another look at it today. The fix may be easy, but this code is subtle. |
This code is certainly subtle! If we don't get to this before the RC, we should probably prefer a very narrow fix. Thanks for looking into it. |
Change https://go.dev/cl/548395 mentions this issue: |
…list This change restores the original logic in parseParameterList to what it was before CL 538858 (which caused the issue), not in exact wording but in identical semantic meaning, and thus restores this function to a state that we know was working fine. However, the change keeps the improved error reporting introduced by CL 538858. To keep the code changes somewhat minimal as we are close to RC1, the improved error handling exists twice for now even though it could be factored out. Fixes golang#64534. Change-Id: I0b7bbf74d28811e8aae74f838f2d424f78af1f38 Reviewed-on: https://go-review.googlesource.com/c/go/+/548395 Reviewed-by: Alan Donovan <adonovan@google.com> Run-TryBot: Robert Griesemer <gri@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Discovered via Google internal bug reporting, and reproduced via fuzzing.
The following code panics in object resolution:
Output:
https://go.dev/play/p/SacseHmo6ha?v=gotip
This is a new regression, and does not reproduce at 1.21. Marking as a release blocker.
The only thing that changed is https://go.dev/cl/538858, though I don't immediately see the bug.
CC @griesemer @adonovan
The text was updated successfully, but these errors were encountered: