Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions go/ql/lib/semmle/go/Types.qll
Original file line number Diff line number Diff line change
Expand Up @@ -517,17 +517,23 @@ class StructType extends @structtype, CompositeType {
.getOwnField(name, isEmbedded)
}

// Materialize the embedded fields and their types before joining them with methods.
pragma[nomagic]
private Type getEmbeddedFieldType(Field embeddedParent, int depth) {
this.hasFieldCand(_, embeddedParent, depth, true) and
result = embeddedParent.getType()
}

/**
* Gets a method of `embeddedParent`, which is then embedded into this struct type.
*/
Method getMethodOfEmbedded(Field embeddedParent, string name, int depth) {
// embeddedParent is a field of 'this' at depth 'depth - 1'
this.hasFieldCand(_, embeddedParent, depth - 1, true) and
result.getName() = name and
(
result.getReceiverBaseType() = lookThroughPointerType(embeddedParent.getType())
// embeddedParent is a field of 'this' at depth 'depth - 1'
exists(Type embeddedType | embeddedType = this.getEmbeddedFieldType(embeddedParent, depth - 1) |
result.getReceiverBaseType() = lookThroughPointerType(embeddedType)
or
methodhosts(result, embeddedParent.getType())
methodhosts(result, embeddedType)
)
}

Expand Down
Loading