Skip to content

go/packages: do not nullify Fset when NeedSyntax is set #506

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

Closed
wants to merge 2 commits into from

Conversation

edigaryev
Copy link
Contributor

@edigaryev edigaryev commented Jul 27, 2024

Currently, Fset is initialized when either NeedTypes or NeedSyntax are set in newLoader().

However, later in refine() it is nullified using a different condition that doesn't take NeedSyntax into account.

Use the inverse condition to that of in newLoader() when deciding on whether to nullify Fset or not.

Resolves golang/go#48226.

@gopherbot
Copy link
Contributor

This PR (HEAD: 78f90b8) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/tools/+/601239.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@edigaryev
Copy link
Contributor Author

edigaryev commented Jul 27, 2024

Copied the markdown description from the first message for humans to see because Gopher Robot complained about it.

Problem

Fset is initialized when either NeedTypes or NeedSyntax are set here:

if ld.Mode&NeedTypes != 0 || ld.Mode&NeedSyntax != 0 {
if ld.Fset == nil {
ld.Fset = token.NewFileSet()
}

However, later, it is nullified on a slightly different condition:

if ld.requestedMode&NeedTypes == 0 {
ld.pkgs[i].Types = nil
ld.pkgs[i].Fset = nil
ld.pkgs[i].IllTyped = false
}

Solution

Use the same but inverse condition when deciding on whether to nullify Fset or not.

Resolves golang/go#48226.

@gopherbot
Copy link
Contributor

Message from Gopher Robot:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/601239.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Nikolay Edigaryev:

Patch Set 1:

(2 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/601239.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Michael Matloob:

Patch Set 2: Code-Review+2


Please don’t reply on this GitHub thread. Visit golang.org/cl/601239.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Alan Donovan:

Patch Set 2: Code-Review+2 Commit-Queue+1

(2 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/601239.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Go LUCI:

Patch Set 2:

Dry run: CV is trying the patch.

Bot data: {"action":"start","triggered_at":"2024-07-31T17:17:07Z","revision":"212b14cbab8f8831b08a16ac8d28371b2be62a30"}


Please don’t reply on this GitHub thread. Visit golang.org/cl/601239.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

This PR (HEAD: a906871) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/tools/+/601239.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot
Copy link
Contributor

Message from Go LUCI:

Patch Set 2: LUCI-TryBot-Result-1


Please don’t reply on this GitHub thread. Visit golang.org/cl/601239.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Nikolay Edigaryev:

Patch Set 3:

(2 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/601239.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Michael Matloob:

Patch Set 3: Code-Review+2 Commit-Queue+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/601239.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Go LUCI:

Patch Set 3:

Dry run: CV is trying the patch.

Bot data: {"action":"start","triggered_at":"2024-08-01T19:56:03Z","revision":"27bae963aaa45c4e71e4cf05364c2f8be3bb437c"}


Please don’t reply on this GitHub thread. Visit golang.org/cl/601239.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Michael Matloob:

Patch Set 3: -Commit-Queue


Please don’t reply on this GitHub thread. Visit golang.org/cl/601239.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Go LUCI:

Patch Set 3:

This CL has passed the run


Please don’t reply on this GitHub thread. Visit golang.org/cl/601239.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Go LUCI:

Patch Set 3: LUCI-TryBot-Result+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/601239.
After addressing review feedback, remember to publish your drafts!

gopherbot pushed a commit that referenced this pull request Aug 5, 2024
Currently, Fset is initialized when either NeedTypes or NeedSyntax are set in newLoader().

However, later in refine() it is nullified using a different condition that doesn't take NeedSyntax into account.

Use the inverse condition to that of in newLoader() when deciding on whether to nullify Fset or not.

Resolves golang/go#48226.

Change-Id: Ic7c05dfe3337d5cf14aa185350a8e766e224c898
GitHub-Last-Rev: a906871
GitHub-Pull-Request: #506
Reviewed-on: https://go-review.googlesource.com/c/tools/+/601239
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
@gopherbot
Copy link
Contributor

This PR is being closed because golang.org/cl/601239 has been merged.

@gopherbot gopherbot closed this Aug 5, 2024
@edigaryev edigaryev deleted the needsyntax-needs-fset branch August 5, 2024 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

x/tools/go/packages: Package.Fset is nil when using NeedSyntax
2 participants