-
Notifications
You must be signed in to change notification settings - Fork 392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: Syntax for read- and write- access to properties #284
RFC: Syntax for read- and write- access to properties #284
Conversation
One corner case is that type inference may deduce different read- and | ||
write-types, which need to be presented to the user. For example the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't seem possible with current inference rules for read-only and write-only properties:
https://github.com/Roblox/luau/blob/master/rfcs/property-writeonly.md#adding-read-only-and-write-only-properties
In the example below, assignment of Dog.new()
to x.pet
will make pet
property read-write.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once we've got local type inference, we'll get different read and write types. In this case we'll get a free type X
with constraints X <: { get pet : Animal }
and X <: { set pet : Dog }
, so solving those constraints gives different read and write types.
* ... as per "names for modifiers", only prefixed by `@` ... | ||
|
||
These both have the advantage of being unambiguous and easier to | ||
parse. Symbols are terser, whch is both good and bad. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a new sigil to Luau is probably not the best course of action here. I vote against @
-attributes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may end up with attribute for things like API documentation, deprecation, etc. The syntax which most languages seem to have adopted is @attribute
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Sorry for the delay, it's been the winter break!)
I think this RFC as proposed leaks too much implementation detail and increases the complexity of type annotation grammar in general. I was hoping that we would arrive at something like:
This also means it's not too confusing because you don't have two fields of the same name with different types with a read/write dichotomy. Even better yet, we don't need to expose the |
@alexmccord We could just provide new syntax for read-only and write-only properties, and then use intersections to construct types with different read and write types. |
This PR is closed as part of RFC migration; please see #1074 (comment) for context. |
Still a draft as we are exploring the design space.