Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Go: fix database inconsistency when receiver has alias type #19464

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

Merged
merged 2 commits into from
May 6, 2025

Conversation

owen-mc
Copy link
Contributor

@owen-mc owen-mc commented May 6, 2025

It was reported that codeql/go/ql/test/library-tests/semmle/go/aliases/InterfaceImpls fails DB-CHECK if you add --check-databases to the test target of codeql/go/Makefile. This turns out to be because that test has a method defined on a receiver which is an alias Impl6Alias of the type Impl6. This is equivalent to defining the method on Impl6 directly. There is some code in the extractor which makes sure that objects which are receiver variables get a special label which is the same when seen from different files. That code was not unaliasing the type of the receiver. This PR fixes that, which fixes the db inconsistency.

I do not think this needs any tests. I also don't think it needs a change note.

I also included a minor drive-by refactor. We were defining our own wrapper around types.Unalias when we don't need to (because it already has the property we want, i.e. being idempotent for non-alias types).

@Copilot Copilot AI review requested due to automatic review settings May 6, 2025 09:50
@owen-mc owen-mc added the no-change-note-required This PR does not need a change note label May 6, 2025
@owen-mc owen-mc requested a review from a team as a code owner May 6, 2025 09:50
@github-actions github-actions bot added the Go label May 6, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR ensures that alias types are unaliased before looking up or labeling methods and types, fixing a database inconsistency when a method receiver uses an alias.

  • Unalias receiver types in findMethodWithGivenReceiver so methods on alias types resolve correctly.
  • Remove resolveTypeAlias helper and replace its uses with types.Unalias in extractType and getTypeLabel.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
go/extractor/trap/labels.go Unalias the receiver’s type before searching for matching methods.
go/extractor/extractor.go Inline alias resolution by replacing resolveTypeAlias with types.Unalias in type extraction and labeling.
Comments suppressed due to low confidence (3)

go/extractor/trap/labels.go:172

  • Add a unit test for findMethodWithGivenReceiver that defines a method on an alias receiver (e.g., Impl6Alias) and verifies the method is found correctly to prevent future regressions.
unaliasedType := types.Unalias(object.Type())

go/extractor/extractor.go:1588

  • Add tests for extractType to confirm alias types are unaliased before labeling, ensuring no alias-related inconsistencies in the database.
tp = types.Unalias(tp)

go/extractor/extractor.go:1766

  • Add tests for getTypeLabel to verify that types supplied via types.Unalias produce consistent labels for both aliased and unaliased inputs.
tp = types.Unalias(tp)

@owen-mc owen-mc merged commit a857069 into github:main May 6, 2025
15 checks passed
@owen-mc owen-mc deleted the go/fix/extract-recv-alias-type branch May 6, 2025 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Go no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants