Skip to content

define_unknown_imports_as_traps fails when a ComponentInstance import is already registered in the linker #13896

Description

@arbourd

I ran into this issue with a component that was importing wasi:io/poll@0.2.12.

wasi:io/poll is already imported via the call to add_to_linker_async.

define_unknown_imports_as_traps should skip already-imported instances, but it appears not to.

This example code is similar to where I experienced the error:

async fn example(component: &[u8]) -> anyhow::Result<()> {
    let engine = Engine::default();
    let mut linker: component::Linker<()> = component::Linker::new(&engine);
    wasmtime_wasi::p2::add_to_linker_async(&mut linker)?;

    // assume component imports `wasi:io/poll
    let component = Component::new(&engine, component)?;

    // errors
    linker.define_unknown_imports_as_traps(&component)?;

    Ok(())
}

Test Case

example.wat

(component
  (import "wasi:io/poll@0.2.12" (instance
    (export "pollable" (type (sub resource)))
  ))
)

Steps to Reproduce

  • wasmtime run -W unknown-imports-trap example.wat

Expected Results

The command fails with no exported instance named.

Error: failed to run main module `example.wat`

Caused by:
    no exported instance named `wasi:io/poll@0.2.12`

Actual Results

The command fails with a defined twice.

Error: failed to run main module `example.wat`

Caused by:
    map entry `wasi:io/poll@0.2.12` defined twice

Versions and Environment

Wasmtime version or commit: wasmtime 46.0.1 (823d1b8 2026-06-24)

Operating system: macOS 26.5.2

Architecture: arm64

Extra Info

The naive example above is an attempt to recreate the error I experienced in Rust.

I hope it captures the problem I experienced and isn't a distraction. If it doesn't make sense, I can attempt to provide a better example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIncorrect behavior in the current implementation that needs fixing

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions