Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions design/mvp/Binary.md
Original file line number Diff line number Diff line change
Expand Up @@ -444,20 +444,23 @@ Notes:
unless the name is also annotated with `[method]`, in which case `self` must
be the only parameter (subject to the `[method]` validation rules above).
* 📡 Validation of `[get]` names requires that the function have a result type.
If the result type is `(result $V? (error $E)?)`, then it must have an inner
value type (and may or may not have an error type).
* 📡 A getter's *property type* is its result type, except that if the result
type is `(result $V (error $E)?)`, the property type is `$V`. (In other
words, the property type "unwraps" the result type.)
* 📡 If a name with `[set]` is defined as an import or export within a
particular scope, it must be preceded by a corresponding `[get]` in the same
scope. That is, there must already be an import or export respectively in the
same scope where the entire name is identical (*before* canonicalization),
except that the `[set]` annotation is replaced with `[get]`.
* 📡 Validation of `[set]` names requires that the function have exactly one
parameter, unless the name is also annotated with `[method]`, in which case
there must be two parameters, the first of which is `self` (subject to the
`[method]` validation rules above).
`[method]` validation rules above). The type of this parameter must match the
corresponding getter's *property type*.
Comment thread
lukewagner marked this conversation as resolved.
* 📡 Validation of `[set]` names requires that the function have either no
result type or a result type of `(result (error $E)?)`.
* 📡 If a name with `[set]` is defined as an import or export within a
particular scope, the equivalent name with `[get]` must have already been
defined as an import or export respectively in that same scope—that is, all
labels must be equal (before canonicalization), and all annotations must be
the same except that `[set]` is replaced with `[get]`, and the `[get]`
import/export must precede the `[set]` import/export. For example,
`[set]prop` requires `[get]prop`, and `[method][set]foo.bar` requires
`[method][get]foo.bar`.
result type or a result type of `(result (error $E)?)` (with no value type).
* 🔀/📡 Functions with `[get]` or `[set]` names must not be `async`.
* 🔗 Validation requires that `versionsuffix` is preceded by an `interfaceversion`
matching `canonversion` and that the concatenation of the `canonversion` and
Expand Down
11 changes: 6 additions & 5 deletions design/mvp/Explainer.md
Original file line number Diff line number Diff line change
Expand Up @@ -2773,7 +2773,7 @@ the native JavaScript bindings could look.

To restrict the set of cases that bindings generators need to consider, these
annotations trigger additional type-validation rules (listed in detail in
[Binary.md](Binary.md)):
[Binary.md](Binary.md#import-and-export-definitions)):
* A `[constructor]` import or export named `R` must be a function whose result
type is `(own $R)` or `(result (own $R) (error <valtype>)?)`, where `$R` is
the index of the resource type named `R`.
Expand All @@ -2783,10 +2783,11 @@ annotations trigger additional type-validation rules (listed in detail in
* A `[static]` import or export named `R.foo` must be a function, and `R` must
be the name of a resource type.
* 📡 A `[get]` import or export must have no parameters (besides the required
`self` parameter from `[method]`), and must have a result type.
* 📡 A `[set]` import or export must have exactly one parameter (besides the
required `self` parameter from `[method]`), and must have either no result
type or a result type of `(result (error <valtype>)?)`.
`self` parameter from `[method]`), and must return a value.
* 📡 A `[set]` import or export must be preceded by a matching `[get]` import
or export, must have exactly one parameter (besides the required `self`
parameter from `[method]`) whose type matches the getter's return type, and
must return either nothing or `(result (error <valtype>)?)`.

The `valid semver` production is as defined by the [Semantic Versioning 2.0]
spec and is meant to be interpreted according to that specification. The use of
Expand Down
25 changes: 12 additions & 13 deletions design/mvp/WIT.md
Original file line number Diff line number Diff line change
Expand Up @@ -1579,11 +1579,11 @@ explainer](Concurrency.md#summary).

📡 As syntactic sugar, functions can be declared as *getters* or *setters* by
replacing the `func` keyword with `get` or `set`. Such functions cannot be
async and have additional restrictions on their parameters and results. A `get`
function must have no parameters and must return a value. A `set` function
must have exactly one parameter and must not return a value unless that value
is of type `result<_, error?>`. Every setter must have a corresponding getter
with the same name. For example, the following definitions:
async and have additional restrictions on their parameters and results as
defined in [Binary.md](Binary.md#import-and-export-definitions). Each setter
must have a corresponding getter with the same name (not just equal under
[strong uniqueness](Explainer.md#name-uniqueness)), though in WIT the getter
and setter may appear in any order. For example, the following definitions:

```wit
foo: func(x: u32);
Expand Down Expand Up @@ -1799,12 +1799,11 @@ explicitly-written return type which must be of the form `result<r, ...>` where
written return type and are given the implicit return type `r`.

📡 A resource statement can also contain any number of *getters* and
*setters*, which may or may not be static. Non-static getters and setters also
implicitly take a `self` parameter. Getters take no parameters (besides the
implicit `self` parameter) and must return a value. Setters take exactly one
parameter (besides the implicit `self` parameter) and must not return a value
unless that value is of type `result<_, error?>`. Every setter must have a
corresponding getter with the same name and same static-ness.
*setters*, which may or may not be static. Every setter must have a
corresponding getter with the same name (not just equal under [strong
uniqueness](Explainer.md#name-uniqueness)) and same static-ness, though the two
may appear in any order. The parameter and return types of getters and setters
have extra restrictions defined in [Binary.md](Binary.md#import-and-export-definitions).

For example, the following resource definitions:

Expand All @@ -1816,15 +1815,15 @@ resource blob {
merge: static func(lhs: borrow<blob>, rhs: borrow<blob>) -> blob;
position: get() -> u64; // 📡
position: set(value: u64); // 📡
max-size: static get() -> u64; // 📡
max-size: static get() -> result<u64>; // 📡
max-size: static set(value: u64) -> result<_, string>; // 📡
}
resource blob2 {
constructor(init: list<u8>) -> result<blob2>;
}
```

desugar into:
will desugar into:

```wit
resource blob;
Expand Down
Loading