diff --git a/ql/src/semmle/go/controlflow/ControlFlowGraphImpl.qll b/ql/src/semmle/go/controlflow/ControlFlowGraphImpl.qll index 07a043bdce0..70685046777 100644 --- a/ql/src/semmle/go/controlflow/ControlFlowGraphImpl.qll +++ b/ql/src/semmle/go/controlflow/ControlFlowGraphImpl.qll @@ -48,13 +48,13 @@ private predicate isCond(Expr e) { e = any(ParenExpr par | isCond(par)).getExpr() } -private class PromotedField extends Field { - PromotedField() { this = any(StructType t).getFieldOfEmbedded(_, _, _, _) } +private Type getSelectedStructType(PromotedFieldSelector e) { + pragma[only_bind_into](result) = e.getBase().getType().getBaseType*().getUnderlyingType() } -private predicate implicitFieldSelection(SelectorExpr e, int i, Field implicitField) { +private predicate implicitFieldSelection(PromotedFieldSelector e, int i, Field implicitField) { exists(StructType baseType, PromotedField child | - baseType = e.getBase().getType().getBaseType*().getUnderlyingType() and + baseType = getSelectedStructType(e) and ( e.refersTo(child) or @@ -65,6 +65,14 @@ private predicate implicitFieldSelection(SelectorExpr e, int i, Field implicitFi ) } +private class PromotedFieldSelector extends SelectorExpr { + PromotedFieldSelector() { this.refersTo(any(PromotedField f)) } +} + +private class PromotedField extends Field { + PromotedField() { this = any(StructType t).getFieldOfEmbedded(_, _, _, _) } +} + /** * A node in the intra-procedural control-flow graph of a Go function or file. *