mirror of
https://github.com/luau-lang/rfcs.git
synced 2025-05-04 10:43:48 +01:00
Fix property-readonly.md using old syntax
Replaces all mentions of the old `get property` syntax to `read property`
This commit is contained in:
parent
6c47f8d595
commit
c658fa3e3b
1 changed files with 11 additions and 11 deletions
|
@ -27,7 +27,7 @@ Add a modifier to table properties indicating that they are read-only.
|
||||||
|
|
||||||
This proposal is not about syntax, but it will be useful for examples to have some. Write:
|
This proposal is not about syntax, but it will be useful for examples to have some. Write:
|
||||||
|
|
||||||
* `get p: T` for a read-only property of type `T`.
|
* `read p: T` for a read-only property of type `T`.
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
```luau
|
```luau
|
||||||
|
@ -37,7 +37,7 @@ end
|
||||||
```
|
```
|
||||||
has inferred type:
|
has inferred type:
|
||||||
```
|
```
|
||||||
f: (t: { p: number, get q: number }) -> ()
|
f: (t: { p: number, read q: number }) -> ()
|
||||||
```
|
```
|
||||||
indicating that `p` is used read-write but `q` is used read-only.
|
indicating that `p` is used read-write but `q` is used read-only.
|
||||||
|
|
||||||
|
@ -45,27 +45,27 @@ indicating that `p` is used read-write but `q` is used read-only.
|
||||||
|
|
||||||
Read-only properties are covariant:
|
Read-only properties are covariant:
|
||||||
|
|
||||||
* If `T` is a subtype of `U` then `{ get p: T }` is a subtype of `{ get p: U }`.
|
* If `T` is a subtype of `U` then `{ read p: T }` is a subtype of `{ read p: U }`.
|
||||||
|
|
||||||
Read-write properties are a subtype of read-only properties:
|
Read-write properties are a subtype of read-only properties:
|
||||||
|
|
||||||
* If `T` is a subtype of `U` then `{ p: T }` is a subtype of `{ get p: U }`.
|
* If `T` is a subtype of `U` then `{ p: T }` is a subtype of `{ read p: U }`.
|
||||||
|
|
||||||
### Indexers
|
### Indexers
|
||||||
|
|
||||||
Indexers can be marked read-only just like properties. In
|
Indexers can be marked read-only just like properties. In
|
||||||
particular, this means there are read-only arrays `{get T}`, that are
|
particular, this means there are read-only arrays `{read T}`, that are
|
||||||
covariant, so we have a solution to the "covariant array problem":
|
covariant, so we have a solution to the "covariant array problem":
|
||||||
|
|
||||||
```luau
|
```luau
|
||||||
local dogs: {Dog}
|
local dogs: {Dog}
|
||||||
function f(a: {get Animal}) ... end
|
function f(a: {read Animal}) ... end
|
||||||
f(dogs)
|
f(dogs)
|
||||||
```
|
```
|
||||||
|
|
||||||
It is sound to allow this program, since `f` only needs read access to
|
It is sound to allow this program, since `f` only needs read access to
|
||||||
the array, and `{Dog}` is a subtype of `{get Dog}`, which is a subtype
|
the array, and `{Dog}` is a subtype of `{read Dog}`, which is a subtype
|
||||||
of `{get Animal}`. This would not be sound if `f` had write access,
|
of `{read Animal}`. This would not be sound if `f` had write access,
|
||||||
for example `function f(a: {Animal}) a[1] = Cat.new() end`.
|
for example `function f(a: {Animal}) a[1] = Cat.new() end`.
|
||||||
|
|
||||||
### Functions
|
### Functions
|
||||||
|
@ -80,8 +80,8 @@ function t:m() ... end
|
||||||
should have type
|
should have type
|
||||||
```
|
```
|
||||||
t : {
|
t : {
|
||||||
get f : () -> (),
|
read f : () -> (),
|
||||||
get m : (self) -> ()
|
read m : (self) -> ()
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ since the build method is read-write, so users can update it:
|
||||||
|
|
||||||
but if we define:
|
but if we define:
|
||||||
```luau
|
```luau
|
||||||
type ROFactory<A> = { get build : () -> A }
|
type ROFactory<A> = { read build : () -> A }
|
||||||
```
|
```
|
||||||
|
|
||||||
then we do have that `ROFactory<Dog>` is a subtype of `ROFactory<Animal>`
|
then we do have that `ROFactory<Dog>` is a subtype of `ROFactory<Animal>`
|
||||||
|
|
Loading…
Add table
Reference in a new issue