codeql icon indicating copy to clipboard operation
codeql copied to clipboard

Go: fix `DefinedType.getBaseType`

Open owen-mc opened this issue 5 months ago • 0 comments
trafficstars

Consider this situation:

type T1 = T2

type T2 struct {}

Previously, DefinedType.getBaseType just gave the underlying type, so calling it on T1 would give struct {}. This PR fixes it so that DefinedType.getBaseType gives the right hand side of the type declaration, and hence calling it on T1 gives T2.

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.getBaseType outside of the definition of DefinedType, and added a proper test for DefinedType.getBaseType.

owen-mc avatar Jun 03 '25 14:06 owen-mc