From 8abad9a07d2c73fcabd2f0b034d907aea4a80041 Mon Sep 17 00:00:00 2001 From: "ajeffrey@roblox.com" Date: Mon, 20 Sep 2021 15:36:58 -0500 Subject: [PATCH] Added more discussion about an alternative to separate getter/setters. --- rfcs/property-getter-setter.md | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/rfcs/property-getter-setter.md b/rfcs/property-getter-setter.md index 84a58d83..d5751f11 100644 --- a/rfcs/property-getter-setter.md +++ b/rfcs/property-getter-setter.md @@ -175,6 +175,23 @@ who will be faced with get/set modifiers on many properties. Rather than making read-write access the default, we could make read-only the default and add a new modifier for read-write. This is not backwards compatible. -Rather than separate getter and setter types, we could have one type with -a read/write annotation. This would re-introduce invariance, and there are -programs which would no longer typecheck. +Rather than separate getter and setter types, we could have one type +with a read/write annotation. This would re-introduce invariance, and +would not allow the example program to typecheck. + +There is a trade-off here, between reporting a type error in cases +like this, or inferring a type with separate getters and setters. Both +of these introduce complexity: + +* If we report a type error, the user has to work out why this is an + error, and how to fix it. In order to understand why it is an error, + the user needs to understand subtyping and the variance rules for + properties. + +* If we infer separate getters and setters, the user will be faced + with types with separate getters and setters in error messages and + type hover. + +This is a tricky trade-off, as we are deciding for the user how to +spend their complexity budget. +