From d6b4c7973633b820fd0038d52a87198a4f21c312 Mon Sep 17 00:00:00 2001 From: Celestino Amoroso Date: Mon, 17 Jun 2024 09:05:23 +0200 Subject: [PATCH] operator-index.go: dict item access by generic keys implemented --- operator-index.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/operator-index.go b/operator-index.go index 565029c..2888d9b 100644 --- a/operator-index.go +++ b/operator-index.go @@ -113,6 +113,16 @@ func evalIndex(ctx ExprContext, self *term) (v any, err error) { default: 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 }