Dict literal now accepts expressions as keys. Key values are computed at evalutetion time and still must be integer or string

This commit is contained in:
2026-05-20 05:14:22 +02:00
parent 1aea1c14d2
commit 1055569dd6
6 changed files with 60 additions and 46 deletions
+8 -3
View File
@@ -39,11 +39,16 @@ func TestDictParser(t *testing.T) {
/* 16 */ {`D={1:"a"}; D.2`, nil, `[1:15] key 2 not found`},
/* 17 */ {`D={1:"a"}; D."2"`, nil, `[1:17] key "2" not found`},
/* 18 */ {`D={"a":1, "b":2}; D.a = 10; D.a`, int64(10), nil},
// /* 19 */ {`D={"a": {"one": 1}}; D.a."one" = 10; D["a"]["one"]`, int64(10), nil},
/* 19 */ {`k="a"; D={k: 10}`, kern.NewDict(map[any]any{"a": int64(10)}), nil},
/* 20 */ {`k=[<1,2>]; D={k: 10}`, nil, `[1:16] dict key can be integer or string, got lisked-list`},
/* 21 */ {`f=func(n){"x"+n}; d{f(5):10}`, nil, `[0:0] two adjacent operators: "d" and "{}"`},
/* 22 */ {`f=func(n){"x"+n}; d={f(5):10}`, kern.NewDict(map[any]any{"x5": int64(10)}), nil},
/* 23 */ {`f=func(n){"x"+n}; d={f(5); "z":10}`, nil, "[1:27] expected one of `:`, `}`, got `;`"},
/* 24 */ {`f=func(n){"x"+n}; d={f(5) but "z":10}`, kern.NewDict(map[any]any{"z": int64(10)}), nil},
}
// runTestSuiteSpec(t, section, inputs, 16)
runTestSuite(t, section, inputs)
runTestSuiteSpec(t, section, inputs, 1, 23, 24)
// runTestSuite(t, section, inputs)
}
func TestAccessSubFields(t *testing.T) {