diff --git a/design/mvp/Binary.md b/design/mvp/Binary.md index 9a022d72..2e39551e 100644 --- a/design/mvp/Binary.md +++ b/design/mvp/Binary.md @@ -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*. * πŸ“‘ 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 diff --git a/design/mvp/Explainer.md b/design/mvp/Explainer.md index b290b14e..595d3cd4 100644 --- a/design/mvp/Explainer.md +++ b/design/mvp/Explainer.md @@ -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 )?)`, where `$R` is the index of the resource type named `R`. @@ -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 )?)`. + `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 )?)`. 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 diff --git a/design/mvp/WIT.md b/design/mvp/WIT.md index 4fa25639..1f5ce56b 100644 --- a/design/mvp/WIT.md +++ b/design/mvp/WIT.md @@ -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); @@ -1799,12 +1799,11 @@ explicitly-written return type which must be of the form `result` 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: @@ -1816,7 +1815,7 @@ resource blob { merge: static func(lhs: borrow, rhs: borrow) -> blob; position: get() -> u64; // πŸ“‘ position: set(value: u64); // πŸ“‘ - max-size: static get() -> u64; // πŸ“‘ + max-size: static get() -> result; // πŸ“‘ max-size: static set(value: u64) -> result<_, string>; // πŸ“‘ } resource blob2 { @@ -1824,7 +1823,7 @@ resource blob2 { } ``` -desugar into: +will desugar into: ```wit resource blob;