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
Using an interface for two imports causes an error #529
This is currently intended, yes, although perhaps not with the best error message. Additionally the specification for WIT.md in the component-model repository should probably have more words about this. @lukewagner would be able to explain in more detail where this restriction comes from.
The basic idea (described more here) is that each import/export name has two parts, a developer-facing kebab-case string (meant to be converted into source-code bindings) and an optional (id <URL>) field which, when present, is meant to uniquely identify the (standards- or vendor-defined) interface that is being requested/implemented. The id is supposed to uniquely determine what is being requested, so that two imports of the same id can always be de-duplicated. But if a component can import the same id twice, that would imply that extra context is being used to identify the interface and thus duplicate imports/exports of the same id is disallowed. In your first example, self.iface turned into an id, hence the duplicate error, while, in the second example, because the interfaces are anonymous/inline, there is no id.
A better error message could help of course, but I do wonder if we should make it more explicit when an import/export includes an id or not.
Activity
alexcrichton commentedon Mar 6, 2023
This is currently intended, yes, although perhaps not with the best error message. Additionally the specification for
WIT.mdin thecomponent-modelrepository should probably have more words about this. @lukewagner would be able to explain in more detail where this restriction comes from.surma commentedon Mar 6, 2023
Interesting! Yeah I’d love to hear more context. It’s especially confusing because it works just fine™️ if you spell out the interfaces:
lukewagner commentedon Mar 6, 2023
The basic idea (described more here) is that each import/export name has two parts, a developer-facing kebab-case string (meant to be converted into source-code bindings) and an optional
(id <URL>)field which, when present, is meant to uniquely identify the (standards- or vendor-defined) interface that is being requested/implemented. Theidis supposed to uniquely determine what is being requested, so that two imports of the sameidcan always be de-duplicated. But if a component can import the sameidtwice, that would imply that extra context is being used to identify the interface and thus duplicate imports/exports of the sameidis disallowed. In your first example,self.ifaceturned into anid, hence the duplicate error, while, in the second example, because the interfaces are anonymous/inline, there is noid.A better error message could help of course, but I do wonder if we should make it more explicit when an import/export includes an
idor not.