Skip to content

Commit

Permalink
declare world-level type exports before function imports (#135)
Browse files Browse the repository at this point in the history
This avoids a declaration ordering issue if an imported function refers to an
exported type (e.g. as a parameter or result type).

Fixes #134

Signed-off-by: Joel Dice <[email protected]>
  • Loading branch information
dicej authored Dec 20, 2024
1 parent 3b5ef2e commit c50822c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1986,8 +1986,8 @@ from ..types import Result, Ok, Err, Some
"{docs}{python_imports}
from .types import Result, Ok, Err, Some
{imports}
{function_imports}
{type_exports}
{function_imports}
{protocol}
"
)?;
Expand Down
7 changes: 7 additions & 0 deletions src/test/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ pub struct ThingList(Vec<u8>);
pub struct ThingString(String);
pub struct MyFloat(f64);

#[async_trait]
impl TestsImports for Ctx {
async fn output(&mut self, _: Frame) -> Result<()> {
unreachable!()
}
}

macro_rules! load_guest_code {
($($input_string:expr),*) => {
&[
Expand Down
6 changes: 6 additions & 0 deletions src/test/wit/tests.wit
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,10 @@ world tests {
export add: func(a: borrow<float>, b: borrow<float>) -> own<float>;

export read-file: func(path: string) -> result<list<u8>, string>;

record frame {
id: s32,
}

import output: func(frame: frame);
}

0 comments on commit c50822c

Please sign in to comment.