CHORE: Replace parser.ParseDir with golang.org/x/tools/go/packages#4195
Open
philpennock wants to merge 1 commit intoStackExchange:mainfrom
Open
CHORE: Replace parser.ParseDir with golang.org/x/tools/go/packages#4195philpennock wants to merge 1 commit intoStackExchange:mainfrom
philpennock wants to merge 1 commit intoStackExchange:mainfrom
Conversation
parser.ParseDir is deprecated since Go 1.25. Use packages.Load with NeedTypes and NeedTypesInfo to correctly extract CanUse* constant integer values via TypesInfo.Defs, preserving the test's ability to detect missing providerCapabilityChecks entries. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
parser.ParseDir is deprecated since Go 1.25. Use packages.Load with NeedTypes and NeedTypesInfo to correctly extract CanUse* constant integer values via TypesInfo.Defs, preserving the test's ability to detect missing providerCapabilityChecks entries.
This is a replacement PR for #4154. I took my review feedback from that PR, copied the markdown into two local files, and prompted Claude Code (using Sonnet 4.6) with:
The next section is choice quotes from Claude's analysis while working, and the final section was Claude's summary at end-of-work.
I have independently reviewed the code, it looks good, and I've validated that the tests look reasonable and correctly fail when a test is commented out (to ensure the AI did not fabricate that). I think this is a sane way forward.
I thought it would be amusing to use Claude to critique Claude's earlier work.
Now I understand the problem clearly. The broken PR sets
capabilityInts[name.Name] = 0for all constants (the comment even admits it), which means everyCanUse*constant maps toint 0, and sincecapIntsToNames[0]finds the first entry, all checks pass trivially. The test is completely neutered.The fix is to use
packages.NeedTypes/NeedTypesInfo(already requested in the config) to actually read the integer values of the constants. Let me look at the providers package to understand the constants:[...]
The problem is clear. The broken PR:
packages.Loadcorrectly to get type info (NeedTypes,NeedTypesInfo)capabilityIntsto0, making everyCanUse*constant map toCanAutoDNSSEC(which is incapIntsToNames[0]), so all checks pass triviallyThe fix is to use
providers.TypesInfo.Defsto look up the actual*types.Constvalue for each constant. Let me write the corrected test file:Both validations from the review pass:
(4),(9), etc.) and each is paired with its correct record type — matches the "before" output exactly.FAILwithMISSING: providers.CanUseDNAME (9).What was wrong in the PR: The code switched from
parser.ParseDirtopackages.Loadcorrectly, but the author gave up on extracting real integer values and wrotecapabilityInts[name.Name] = 0for everything. Since all constants got value0, they all matchedcapIntsToNames[0] = AUTODNSSEC, making the test trivially pass regardless of what was inproviderCapabilityChecks.The fix: Instead of iterating the raw AST and guessing values, use
providers.TypesInfo.Defs(which is whatNeedTypesInfoprovides) to look up each identifier's*types.Constobject and callconstant.Int64Val(c.Val())to get the actual iota integer.