Go: fix DefinedType.getBaseType#19654
Merged
owen-mc merged 5 commits intogithub:mainfrom Jun 25, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR changes DefinedType.getBaseType to return the alias’s right‐hand side (the declared type) rather than its underlying type, updates related methods to maintain correct semantics, and refreshes library tests accordingly.
- Reimplement
getBaseTypeto read from the declaration AST so aliases return their RHS. - Update
getMethodandgetUnderlyingTypeto use the new separation between base and underlying types. - Revise existing method‐resolution tests and add new tests for
getBaseType.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| go/ql/test/library-tests/semmle/go/Types/MethodTypes.ql | Use Type.hasMethod and add a declaration existence check |
| go/ql/test/library-tests/semmle/go/Types/MethodTypes.expected | Adjust expected methods list after alias semantics change |
| go/ql/test/library-tests/semmle/go/Types/DefinedType_getBaseType.ql | New test querying DefinedType.getBaseType() |
| go/ql/test/library-tests/semmle/go/Types/DefinedType_getBaseType.expected | Expected output for the new getBaseType test |
| go/ql/lib/semmle/go/Types.qll | Change getBaseType, getUnderlyingType, and related logic |
Comments suppressed due to low confidence (1)
go/ql/test/library-tests/semmle/go/Types/DefinedType_getBaseType.ql:4
- Consider adding a test case to verify that
getBaseTypereturns no result for types declared in external packages, ensuring the new behavior is validated against external definitions.
where tp = dt.getBaseType()
9535baf to
b2f310c
Compare
smowton
approved these changes
Jun 25, 2025
Contributor
smowton
left a comment
There was a problem hiding this comment.
Have taken the liberty of committing Copilot's suggested change (spelling fix). Otherwise looks plausible; suggest DCA against any accidental semantic change.
Contributor
Author
|
DCA looks fine. |
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.
Consider this situation:
Previously,
DefinedType.getBaseTypejust gave the underlying type, so calling it onT1would givestruct {}. This PR fixes it so thatDefinedType.getBaseTypegives the right hand side of the type declaration, and hence calling it onT1givesT2.Note that this requires us to have extracted the declaration of the type, so it is only available for types declared in the project being analyzed. It is not defined for types defined in external packages. Since this information is not stored in the information that we already extract for external packages, I cannot see any way to improve this situation except for expanding what we look at from external packages.
I have also fixed a test which was the only use of
DefinedType.getBaseTypeoutside of the definition ofDefinedType, and added a proper test forDefinedType.getBaseType.