From 38cc1f08157ef3d246ee0e2c64bcc785d344212e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D0=BA=D1=82=D0=BE=D1=80=20=D0=91=D1=8B=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=BE=D0=B2?= Date: Thu, 12 Nov 2026 10:36:15 +0500 Subject: [PATCH] docs: explain map literal key types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Виктор Быстров --- docs/language-definition.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/language-definition.md b/docs/language-definition.md index 69efbdfa9..56ca9cce8 100644 --- a/docs/language-definition.md +++ b/docs/language-definition.md @@ -111,6 +111,22 @@ Unlike string literals, bytes literals do not support `\u` or `\U` Unicode escap Use `\x` escapes for arbitrary byte values. ::: +### Maps + +Map literals create `map[string]any` values. Unquoted identifier keys are treated as strings, and numeric keys are +converted to strings. Use string keys when indexing a map literal or testing membership: + +```expr +{name: "John"}.name // "John" +{1: "one"}["1"] // "one" +"1" in {1: "one"} // true +``` + +Using an integer key, as in `{1: "one"}[1]` or `1 in {1: "one"}`, produces a type error. + +Go maps supplied through the [environment](environment.md) keep their declared key type. For a value `numbers` of type +`map[int]string`, use `numbers[1]` and `1 in numbers`. + ## Operators