Skip to content

Commit 0e94ee8

Browse files
committed
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.
1 parent 2cba97e commit 0e94ee8

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

go/ql/lib/semmle/go/Types.qll

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -496,14 +496,15 @@ class StructType extends @structtype, CompositeType {
496496
Field getFieldOfEmbedded(Field embeddedParent, string name, int depth, boolean isEmbedded) {
497497
// embeddedParent is a field of 'this' at depth 'depth - 1'
498498
this.hasFieldCand(_, embeddedParent, depth - 1, true) and
499-
// embeddedParent's type has the result field
500-
exists(StructType embeddedType, Type fieldType |
501-
fieldType = embeddedParent.getType().getUnderlyingType() and
502-
pragma[only_bind_into](embeddedType) =
503-
[fieldType, fieldType.(PointerType).getBaseType().getUnderlyingType()]
504-
|
505-
result = embeddedType.getOwnField(name, isEmbedded)
506-
)
499+
// embeddedParent's type has the result field. Note that it is invalid Go
500+
// to have an embedded field with a named type whose underlying type is a
501+
// pointer, so we don't have to have
502+
// `lookThroughPointerType(embeddedParent.getType().getUnderlyingType())`.
503+
result =
504+
lookThroughPointerType(embeddedParent.getType())
505+
.getUnderlyingType()
506+
.(StructType)
507+
.getOwnField(name, isEmbedded)
507508
}
508509

509510
/**

0 commit comments

Comments
 (0)