Skip to content

Commit fe26efa

Browse files
Simplify the disambiguation logic to a single boolean (#1263)
1 parent 52280ba commit fe26efa

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

interpreter/attributes.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ type attrFactory struct {
166166
// The namespaceNames represent the names the variable could have based on namespace
167167
// resolution rules.
168168
func (r *attrFactory) AbsoluteAttribute(id int64, names ...string) NamespacedAttribute {
169-
disambiguateNames := make(map[int]bool)
169+
disambiguateNames := false
170170
for idx, name := range names {
171171
if strings.HasPrefix(name, ".") {
172-
disambiguateNames[idx] = true
172+
disambiguateNames = true
173173
names[idx] = strings.TrimPrefix(name, ".")
174174
}
175175
}
@@ -259,8 +259,8 @@ type absoluteAttribute struct {
259259
// namespaceNames represent the names the variable could have based on declared container
260260
// (package) of the expression.
261261
namespaceNames []string
262-
// disambiguateNames stores a list of indices to namespaceNames which require disambiguation
263-
disambiguateNames map[int]bool
262+
// disambiguateNames indicates whether the namespaceNames require disambiguation with local variables.
263+
disambiguateNames bool
264264

265265
qualifiers []Qualifier
266266
adapter types.Adapter
@@ -331,19 +331,19 @@ func (a *absoluteAttribute) Resolve(vars Activation) (any, error) {
331331
// Presently, only dynamic and constant slot activations created during comprehensions
332332
// support 'unwrapping', which is consistent with how local variables are introduced into CEL.
333333
var inputVars Activation
334-
if len(a.disambiguateNames) > 0 {
334+
if a.disambiguateNames {
335335
inputVars = vars
336336
wrapped, ok := inputVars.(activationWrapper)
337337
for ok {
338338
inputVars = wrapped.Unwrap()
339339
wrapped, ok = inputVars.(activationWrapper)
340340
}
341341
}
342-
for idx, nm := range a.namespaceNames {
342+
for _, nm := range a.namespaceNames {
343343
// If the variable is found, process it. Otherwise, wait until the checks to
344344
// determine whether the type is unknown before returning.
345345
v := vars
346-
if disambiguate, found := a.disambiguateNames[idx]; found && disambiguate {
346+
if a.disambiguateNames {
347347
v = inputVars
348348
}
349349
obj, found := v.ResolveName(nm)

0 commit comments

Comments
 (0)