Skip to content

Using an interface for two imports causes an error #529

Open

Description

@surma
interface iface {
	f: func()
}

default world w {
	import p1: self.iface
	import p2: self.iface
}

This produces the following error:

$ wit-bindgen markdown example.wit
Error: interface `p2` imported more than once
     --> example.wit:7:9
      |
    7 |         import p2: self.iface
      |

Is it actually not allowed to have two imports with the same interface? That seems surprising to me.

Activity

  1. alexcrichton commented on Mar 6, 2023

    @alexcrichton
    Member

    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.

  2. surma commented on Mar 6, 2023

    @surma
    ContributorAuthor

    Interesting! Yeah I’d love to hear more context. It’s especially confusing because it works just fine™️ if you spell out the interfaces:

    default world w {
    	import p1: interface {
    		f: func()
    	}
    	import p2: interface {
    		f: func()
    	}
    }
  3. lukewagner commented on Mar 6, 2023

    @lukewagner

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions