Skip to content

Commit c7d6d39

Browse files
authored
Merge pull request #22995 from owen-mc/go/fix-dca-tuple-sum-noise-2
Go: reduce intermediate tuples in embedded method resolution
2 parents 79ef8bc + e1083dd commit c7d6d39

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,17 +517,23 @@ class StructType extends @structtype, CompositeType {
517517
.getOwnField(name, isEmbedded)
518518
}
519519

520+
// Materialize the embedded fields and their types before joining them with methods.
521+
pragma[nomagic]
522+
private Type getEmbeddedFieldType(Field embeddedParent, int depth) {
523+
this.hasFieldCand(_, embeddedParent, depth, true) and
524+
result = embeddedParent.getType()
525+
}
526+
520527
/**
521528
* Gets a method of `embeddedParent`, which is then embedded into this struct type.
522529
*/
523530
Method getMethodOfEmbedded(Field embeddedParent, string name, int depth) {
524-
// embeddedParent is a field of 'this' at depth 'depth - 1'
525-
this.hasFieldCand(_, embeddedParent, depth - 1, true) and
526531
result.getName() = name and
527-
(
528-
result.getReceiverBaseType() = lookThroughPointerType(embeddedParent.getType())
532+
// embeddedParent is a field of 'this' at depth 'depth - 1'
533+
exists(Type embeddedType | embeddedType = this.getEmbeddedFieldType(embeddedParent, depth - 1) |
534+
result.getReceiverBaseType() = lookThroughPointerType(embeddedType)
529535
or
530-
methodhosts(result, embeddedParent.getType())
536+
methodhosts(result, embeddedType)
531537
)
532538
}
533539

0 commit comments

Comments
 (0)