Skip to content

Commit

Permalink
fix: deserialize LibraryPath for Wasm CM interface named modules
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat committed Dec 18, 2024
1 parent fedea27 commit 280d338
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion assembly/src/library/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use core::{
};

use smallvec::smallvec;
use vm_core::debuginfo::SourceSpan;

use crate::{
ast::{Ident, IdentError},
Expand Down Expand Up @@ -505,7 +506,26 @@ impl Deserializable for LibraryPath {
let path = source.read_slice(len)?;
let path =
str::from_utf8(path).map_err(|e| DeserializationError::InvalidValue(e.to_string()))?;
Self::new(path).map_err(|e| DeserializationError::InvalidValue(e.to_string()))
let path = LibraryPath::new(path).unwrap_or_else(|_| {
// Try to parse at least the namespace
match LibraryNamespace::strip_path_prefix(path) {
Ok((ns, rest)) => {
let module_id = Ident::new_unchecked(Span::new(
SourceSpan::default(),
Arc::from(rest.to_string()),
));
LibraryPath::new_from_components(ns, [module_id])
},
Err(_) => {
let module_id = Ident::new_unchecked(Span::new(
SourceSpan::default(),
Arc::from(path.to_string()),
));
LibraryPath::new_from_components(LibraryNamespace::Anon, [module_id])
},
}
});
Ok(path)
}
}

Expand Down

0 comments on commit 280d338

Please sign in to comment.