operator-dot: added support to access dict value by exprssion; example: D.key, D."key", D.expr

This commit is contained in:
2026-04-30 07:06:20 +02:00
parent 32c0b45255
commit 610e2df5f5
2 changed files with 14 additions and 0 deletions
+11
View File
@@ -44,6 +44,17 @@ func evalDot(ctx kern.ExprContext, opTerm *term) (v any, err error) {
} else {
err = indexTerm.tk.ErrorExpectedGot("identifier")
}
case *kern.DictType:
s := opTerm.children[1].symbol()
if s == SymVariable || s == SymString {
src := opTerm.children[1].Source()
if len(src) > 1 && src[0] == '"' && src[len(src)-1] == '"' {
src = src[1 : len(src)-1]
}
v, err = unboxedValue.GetItem(src)
} else if rightValue, err = opTerm.children[1].Compute(ctx); err == nil {
v, err = unboxedValue.GetItem(rightValue)
}
default:
if rightValue, err = opTerm.children[1].Compute(ctx); err == nil {
err = opTerm.errIncompatibleTypes(leftValue, rightValue)