Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4297566

Browse files
test: support AssertUnlinkable
Signed-off-by: Henry Gressmann <[email protected]>
1 parent ed1e181 commit 4297566

File tree

5 files changed

+54
-38
lines changed

5 files changed

+54
-38
lines changed

crates/tinywasm/src/error.rs

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,6 @@ pub enum Error {
4545

4646
/// The store is not the one that the module instance was instantiated in
4747
InvalidStore,
48-
49-
/// Missing import
50-
MissingImport {
51-
/// The module name
52-
module: String,
53-
/// The import name
54-
name: String,
55-
},
56-
57-
/// Could not resolve an import
58-
CouldNotResolveImport {
59-
/// The module name
60-
module: String,
61-
/// The import name
62-
name: String,
63-
},
6448
}
6549

6650
#[derive(Debug)]
@@ -74,7 +58,7 @@ pub enum LinkingError {
7458
name: String,
7559
},
7660
/// A mismatched import type was encountered
77-
MismatchedImportType {
61+
IncompatibleImportType {
7862
/// The module name
7963
module: String,
8064
/// The import name
@@ -166,7 +150,7 @@ impl LinkingError {
166150
pub fn message(&self) -> &'static str {
167151
match self {
168152
Self::UnknownImport { .. } => "unknown import",
169-
Self::MismatchedImportType { .. } => "mismatched import type",
153+
Self::IncompatibleImportType { .. } => "incompatible import type",
170154
}
171155
}
172156
}
@@ -202,14 +186,6 @@ impl Display for Error {
202186
Self::LabelStackUnderflow => write!(f, "label stack underflow"),
203187
Self::StackUnderflow => write!(f, "stack underflow"),
204188
Self::InvalidStore => write!(f, "invalid store"),
205-
206-
Self::MissingImport { module, name } => {
207-
write!(f, "missing import: {}.{}", module, name)
208-
}
209-
210-
Self::CouldNotResolveImport { module, name } => {
211-
write!(f, "could not resolve import: {}.{}", module, name)
212-
}
213189
}
214190
}
215191
}

crates/tinywasm/src/imports.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ impl Imports {
279279
{
280280
if expected != actual {
281281
log::error!("failed to link import {}, expected {:?}, got {:?}", import.name, expected, actual);
282-
return Err(crate::LinkingError::MismatchedImportType {
282+
return Err(crate::LinkingError::IncompatibleImportType {
283283
module: import.module.to_string(),
284284
name: import.name.to_string(),
285285
}
@@ -299,10 +299,11 @@ impl Imports {
299299

300300
for import in module.data.imports.iter() {
301301
let Some(val) = self.take(store, import) else {
302-
return Err(crate::Error::MissingImport {
302+
return Err(crate::LinkingError::UnknownImport {
303303
module: import.module.to_string(),
304304
name: import.name.to_string(),
305-
});
305+
}
306+
.into());
306307
};
307308

308309
match val {
@@ -324,7 +325,7 @@ impl Imports {
324325
}
325326
(Extern::Function(extern_func), ImportKind::Function(ty)) => {
326327
let import_func_type = module.data.func_types.get(*ty as usize).ok_or_else(|| {
327-
crate::Error::CouldNotResolveImport {
328+
crate::LinkingError::IncompatibleImportType {
328329
module: import.module.to_string(),
329330
name: import.name.to_string(),
330331
}
@@ -334,7 +335,7 @@ impl Imports {
334335
imports.funcs.push(store.add_func(extern_func, *ty, idx)?);
335336
}
336337
_ => {
337-
return Err(crate::LinkingError::MismatchedImportType {
338+
return Err(crate::LinkingError::IncompatibleImportType {
338339
module: import.module.to_string(),
339340
name: import.name.to_string(),
340341
}
@@ -346,7 +347,7 @@ impl Imports {
346347
ResolvedExtern::Store(val) => {
347348
// check if the kind matches
348349
if val.kind() != (&import.kind).into() {
349-
return Err(crate::LinkingError::MismatchedImportType {
350+
return Err(crate::LinkingError::IncompatibleImportType {
350351
module: import.module.to_string(),
351352
name: import.name.to_string(),
352353
}

0 commit comments

Comments
 (0)