operator-index.go: dict item access by generic keys implemented
This commit is contained in:
parent
d066344af8
commit
d6b4c79736
@ -113,6 +113,16 @@ func evalIndex(ctx ExprContext, self *term) (v any, err error) {
|
|||||||
default:
|
default:
|
||||||
err = self.errIncompatibleTypes(leftValue, rightValue)
|
err = self.errIncompatibleTypes(leftValue, rightValue)
|
||||||
}
|
}
|
||||||
|
} else if IsDict(leftValue) {
|
||||||
|
var ok bool
|
||||||
|
var indexValue any
|
||||||
|
d := leftValue.(*DictType)
|
||||||
|
if indexValue, err = verifyKey(indexTerm, indexList); err == nil {
|
||||||
|
if v, ok = (*d)[indexValue]; !ok {
|
||||||
|
err = indexTerm.Errorf("key %v does not belong to the dictionary", rightValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user