From f5447a87069aa396ec2c20f02e931f80c82e5cbe Mon Sep 17 00:00:00 2001 From: Andy Friesen Date: Thu, 7 Dec 2023 14:31:34 -0800 Subject: [PATCH] Describe rules surrounding duplicate record fields. --- docs/syntax-property-access-modifiers.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/syntax-property-access-modifiers.md b/docs/syntax-property-access-modifiers.md index 6cfc7c2..9080d96 100644 --- a/docs/syntax-property-access-modifiers.md +++ b/docs/syntax-property-access-modifiers.md @@ -54,6 +54,22 @@ type MixedMap = { read [string]: Animal, write [string]: Dog } type MixedArray = { read Animal, write Dog } ``` +Redundant record fields are still disallowed: Each field may have at most one +read type and one write type: + +```lua +type A = { read x: string, write x: "Hello" } -- OK +type C = { read x: string, read x: "hello" } -- ERROR +type B = { x: string, read x: "hello" } -- ERROR +``` + +We place no restriction on the relationship between the read and write type. +The following is certainly a bad idea, but it is legal: + +```lua +type T = { read n: number, write n: string } +``` + This syntax is readable, matches the flavour of preexisting Luau syntax well, and is pretty easy to parse efficiently.