wac icon indicating copy to clipboard operation
wac copied to clipboard

Support type annotation in WAC

Open salmans opened this issue 1 year ago • 2 comments

When instantiating a component, it's useful to allow the user to provide type annotation that fixes the component's expected imports and exports. For example, in the scenario described in #56, the type annotation can be used to suppress the unknown import error when the import is intended but is not present in the component's WIT, generated by witgen.

salmans avatar Feb 29 '24 22:02 salmans

Proposed syntax might be:

new-expr                ::= 'new' package-name type-ascription? '{' instantiation-args '}'
type-ascription         ::= ':' (id | package-path)

Constraints:

  1. The id or package-path must name a world.
  2. The result of the new expression must be a subtype of the given world.
  3. The ascribed type will be used for validation of the instantiation args.

peterhuene avatar Mar 04 '24 03:03 peterhuene

The : delimiter might be confusing since this would be legal with the above grammar: new foo:bar:foo:bar/baz {}.

Perhaps as instead of :, leading to new foo:bar as foo:bar/baz {}.

peterhuene avatar Mar 12 '24 20:03 peterhuene