Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 27 additions & 14 deletions crates/wasmparser/src/validator/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2446,29 +2446,42 @@ impl ComponentState {
types: &mut TypeAlloc,
offset: usize,
) -> Result<()> {
let component = components.last_mut().unwrap();

match component.kind {
// For a component itself all alias kind are allowed.
ComponentKind::Component => {}

// For instance/component types only aliases to `type` or `instance`
// items are allowed, and all other aliases are rejected.
ComponentKind::InstanceType | ComponentKind::ComponentType => match &alias {
crate::ComponentAlias::InstanceExport {
kind: ComponentExternalKind::Type | ComponentExternalKind::Instance,
..
}
| crate::ComponentAlias::Outer {
kind: ComponentOuterAliasKind::Type | ComponentOuterAliasKind::CoreType,
..
} => {}

_ => bail!(
offset,
"aliases in a component or instance type may only refer to types or instances"
),
},
}

match alias {
crate::ComponentAlias::InstanceExport {
instance_index,
kind,
name,
} => components.last_mut().unwrap().alias_instance_export(
instance_index,
kind,
name,
types,
offset,
),
} => component.alias_instance_export(instance_index, kind, name, types, offset),
crate::ComponentAlias::CoreInstanceExport {
instance_index,
kind,
name,
} => components.last_mut().unwrap().alias_core_instance_export(
instance_index,
kind,
name,
types,
offset,
),
} => component.alias_core_instance_export(instance_index, kind, name, types, offset),
crate::ComponentAlias::Outer { kind, count, index } => match kind {
ComponentOuterAliasKind::CoreModule => {
Self::alias_module(components, count, index, offset)
Expand Down
9 changes: 9 additions & 0 deletions tests/cli/component-model/alias.wast
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,12 @@
(instance (instantiate (component $i "x")))
)
)

(assert_invalid
(component
(type (component
(import "x" (instance $I (export "f" (func))))
(alias export $I "f" (func))
))
)
"aliases in a component or instance type may only refer to types or instances")
7 changes: 7 additions & 0 deletions tests/snapshots/cli/component-model/alias.wast.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@
"line": 293,
"filename": "alias.27.wasm",
"module_type": "binary"
},
{
"type": "assert_invalid",
"line": 304,
"filename": "alias.28.wasm",
"module_type": "binary",
"text": "aliases in a component or instance type may only refer to types or instances"
}
]
}
Loading