mirror of
https://github.com/github/codeql.git
synced 2026-04-20 14:34:04 +02:00
Don't getUnderlyingType before looking through pointer type
If `T` is the type of an embedded field, it is invalid for `T` to be a named type defined to be a pointer type (`type T *S`). It is also invalid for `T` to be a type parameter. So this `getUnderlyingType()` is redundant.
This commit is contained in:
@@ -496,14 +496,15 @@ class StructType extends @structtype, CompositeType {
|
||||
Field getFieldOfEmbedded(Field embeddedParent, string name, int depth, boolean isEmbedded) {
|
||||
// embeddedParent is a field of 'this' at depth 'depth - 1'
|
||||
this.hasFieldCand(_, embeddedParent, depth - 1, true) and
|
||||
// embeddedParent's type has the result field
|
||||
exists(StructType embeddedType, Type fieldType |
|
||||
fieldType = embeddedParent.getType().getUnderlyingType() and
|
||||
pragma[only_bind_into](embeddedType) =
|
||||
[fieldType, fieldType.(PointerType).getBaseType().getUnderlyingType()]
|
||||
|
|
||||
result = embeddedType.getOwnField(name, isEmbedded)
|
||||
)
|
||||
// embeddedParent's type has the result field. Note that it is invalid Go
|
||||
// to have an embedded field with a named type whose underlying type is a
|
||||
// pointer, so we don't have to have
|
||||
// `lookThroughPointerType(embeddedParent.getType().getUnderlyingType())`.
|
||||
result =
|
||||
lookThroughPointerType(embeddedParent.getType())
|
||||
.getUnderlyingType()
|
||||
.(StructType)
|
||||
.getOwnField(name, isEmbedded)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user