You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Disallow [method]... naming unless the resource was defined in the same context #765
But arguably this is a bad idea. This isn't representable in WIT at all and there aren't any actual users of this AFAIK, so I think it would be best to disallow this. In essence only the resource definition should be able to attach methods, because otherwise you could have different instances define the same method and it'd be ambiguous of what to call.
More problematically, however, wasmparser also accepts this:
and this is how wit-component works for any component which exports a resource in an interface. This means that this pattern is widely used meaning that the rule of "must be on the definition" would break a lot of components today.
Ideally wit-component would generate a component that looks like htis:
(component
(type (component
(import"a" (type$a (sub resource)))
(export"r" (type$x (eq $a)) (type (sub resource))) ;; note the type ascription here
(export"[method]r.f" (func (param"self" (borrow $x))))
))
)
I'm also a bit stuck on what "must be next to the definition" means. For example a resource could be declared, then exported, and then methods must be on the type introduced by the export. In that sense some aliases work, but some don't. Hence, the issue here!
In general, agreed that this second (re-export) case you gave is in the same category as the first case and would ideally be rejected too. Incidentally, the new JS API throws in this case specifically to avoid this sort of weird "adding methods to a separately-defined class" case which would otherwise be implied for the JS bindings (and it makes sense that other languages would hit the same weirdness).
For the 3rd component you listed: how do you get WIT to generate that today? I tried a few ways and couldn't (for the same reasons we were thinking it wasn't possible to hit the first case from WIT). And for the 4th component: I'm guessing you didn't mean to have the imports/exports wrapped in a (type (component ... )) so that the export is a non-type-level definition (which is the only place ascription applies)? Assuming that, same question: how would you generate one of these components from WIT today?
I think the "must be next to the definition" condition would apply to every component type (written explicitly as a type definition or inferred from a component definition being validated, just like the "external visibility" rules) and say that the r of an imported/exported [method]r.foo-named function must be preceded in the same immediately-containing instance/component scope as a sub-bound type import/export (respectively!) named r.
Activity
lukewagner commentedon Nov 13, 2026
In general, agreed that this second (re-export) case you gave is in the same category as the first case and would ideally be rejected too. Incidentally, the new JS API throws in this case specifically to avoid this sort of weird "adding methods to a separately-defined class" case which would otherwise be implied for the JS bindings (and it makes sense that other languages would hit the same weirdness).
For the 3rd component you listed: how do you get WIT to generate that today? I tried a few ways and couldn't (for the same reasons we were thinking it wasn't possible to hit the first case from WIT). And for the 4th component: I'm guessing you didn't mean to have the imports/exports wrapped in a
(type (component ... ))so that theexportis a non-type-level definition (which is the only place ascription applies)? Assuming that, same question: how would you generate one of these components from WIT today?I think the "must be next to the definition" condition would apply to every
componenttype (written explicitly as atypedefinition or inferred from a component definition being validated, just like the "external visibility" rules) and say that therof an imported/exported[method]r.foo-named function must be preceded in the same immediately-containinginstance/componentscope as asub-boundtypeimport/export (respectively!) namedr.