mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
fix from wasm32 RocResult implementation
This commit is contained in:
parent
cd2311003e
commit
9cb2bd04fd
4 changed files with 12 additions and 5 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -4795,6 +4795,7 @@ dependencies = [
|
|||
"roc_collections",
|
||||
"roc_constrain",
|
||||
"roc_debug_flags",
|
||||
"roc_error_macros",
|
||||
"roc_gen_dev",
|
||||
"roc_gen_llvm",
|
||||
"roc_gen_wasm",
|
||||
|
|
|
@ -33,6 +33,7 @@ roc_can = { path = "../can" }
|
|||
roc_parse = { path = "../parse" }
|
||||
roc_build = { path = "../build", features = ["target-aarch64", "target-x86_64", "target-wasm32"] }
|
||||
roc_target = { path = "../roc_target" }
|
||||
roc_error_macros = { path = "../../error_macros" }
|
||||
roc_std = { path = "../../roc_std" }
|
||||
roc_debug_flags = {path="../debug_flags"}
|
||||
bumpalo = { version = "3.8.0", features = ["collections"] }
|
||||
|
|
|
@ -308,7 +308,8 @@ fn roc_result_after_on_err() {
|
|||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||
fn roc_result_after_err() {
|
||||
assert_evals_to!(indoc!(
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
result : Result Str I64
|
||||
result =
|
||||
|
@ -316,7 +317,8 @@ fn roc_result_after_err() {
|
|||
if num < 0 then Ok "negative!" else Err -num
|
||||
|
||||
result
|
||||
"#),
|
||||
"#
|
||||
),
|
||||
RocResult::ok(RocStr::from("already a string")),
|
||||
RocResult<RocStr, i64>
|
||||
);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use roc_gen_wasm::wasm32_sized::Wasm32Sized;
|
||||
use roc_error_macros::internal_error;
|
||||
use roc_gen_wasm::{round_up_to_alignment, wasm32_sized::Wasm32Sized};
|
||||
use roc_std::{RocDec, RocList, RocOrder, RocResult, RocStr};
|
||||
use std::convert::TryInto;
|
||||
|
||||
|
@ -99,7 +100,9 @@ where
|
|||
E: FromWasm32Memory + Wasm32Sized,
|
||||
{
|
||||
fn decode(memory: &[u8], offset: u32) -> Self {
|
||||
let tag_offset = Ord::max(T::ACTUAL_WIDTH, E::ACTUAL_WIDTH);
|
||||
let data_align = Ord::max(T::ALIGN_OF_WASM, E::ALIGN_OF_WASM);
|
||||
let data_width = Ord::max(T::ACTUAL_WIDTH, E::ACTUAL_WIDTH);
|
||||
let tag_offset = round_up_to_alignment!(data_width, data_align);
|
||||
let tag = <u8 as FromWasm32Memory>::decode(memory, offset + tag_offset as u32);
|
||||
if tag == 1 {
|
||||
let value = <T as FromWasm32Memory>::decode(memory, offset);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue