Add regression tests for #4772

Closes #4772
This commit is contained in:
Ayaz Hafiz 2023-01-16 14:43:36 -06:00
parent e6926b6fe0
commit 9a4e4f25c2
No known key found for this signature in database
GPG Key ID: 0E2A37416A25EF58
3 changed files with 408 additions and 0 deletions

View File

@ -1805,3 +1805,36 @@ mod eq {
)
}
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn issue_4772_weakened_monomorphic_destructure() {
assert_evals_to!(
indoc!(
r###"
app "test"
imports [Json]
provides [main] to "./platform"
getNumber =
{ result, rest } = Decode.fromBytesPartial (Str.toUtf8 "\"1234\"") Json.fromUtf8
when result is
Ok val ->
when Str.toI64 val is
Ok number ->
Ok {val : number, input : rest}
Err InvalidNumStr ->
Err (ParsingFailure "not a number")
Err _ ->
Err (ParsingFailure "not a number")
main =
getNumber |> Result.map .val |> Result.withDefault 0
"###
),
1234i64,
i64
);
}

View File

@ -0,0 +1,348 @@
procedure Bool.11 (#Attr.2, #Attr.3):
let Bool.23 : Int1 = lowlevel Eq #Attr.2 #Attr.3;
dec #Attr.3;
dec #Attr.2;
ret Bool.23;
procedure Bool.11 (#Attr.2, #Attr.3):
let Bool.24 : Int1 = lowlevel Eq #Attr.2 #Attr.3;
ret Bool.24;
procedure Bool.11 (#Attr.2, #Attr.3):
let Bool.31 : Int1 = lowlevel Eq #Attr.2 #Attr.3;
ret Bool.31;
procedure Bool.11 (#Attr.2, #Attr.3):
let Bool.38 : Int1 = lowlevel Eq #Attr.2 #Attr.3;
ret Bool.38;
procedure Bool.12 (#Attr.2, #Attr.3):
let Bool.30 : Int1 = lowlevel NotEq #Attr.2 #Attr.3;
ret Bool.30;
procedure Bool.7 (Bool.19, Bool.20):
let Bool.29 : Int1 = CallByName Bool.12 Bool.19 Bool.20;
ret Bool.29;
procedure Decode.23 (Decode.94):
ret Decode.94;
procedure Decode.24 (Decode.95, Decode.114, Decode.97):
let Decode.117 : {List U8, [C {}, C Str]} = CallByName Json.293 Decode.95 Decode.97;
ret Decode.117;
procedure Decode.25 (Decode.98, Decode.99):
let Decode.116 : {} = CallByName Json.41;
let Decode.115 : {List U8, [C {}, C Str]} = CallByName Decode.24 Decode.98 Decode.116 Decode.99;
ret Decode.115;
procedure Json.139 (Json.452, Json.453):
joinpoint Json.421 Json.418 Json.138:
let Json.141 : List U8 = StructAtIndex 0 Json.418;
inc Json.141;
let Json.140 : List U8 = StructAtIndex 1 Json.418;
inc Json.140;
dec Json.418;
let Json.422 : [C {}, C U8] = CallByName List.9 Json.141;
let Json.436 : U8 = 1i64;
let Json.437 : U8 = GetTagId Json.422;
let Json.438 : Int1 = lowlevel Eq Json.436 Json.437;
if Json.438 then
let Json.142 : U8 = UnionAtIndex (Id 1) (Index 0) Json.422;
let Json.424 : Int1 = CallByName Json.283 Json.142;
if Json.424 then
let Json.434 : U64 = 1i64;
let Json.430 : {List U8, List U8} = CallByName List.52 Json.141 Json.434;
let Json.431 : {} = Struct {};
let Json.428 : List U8 = CallByName Json.143 Json.430;
let Json.429 : List U8 = CallByName List.4 Json.140 Json.142;
let Json.426 : {List U8, List U8} = Struct {Json.428, Json.429};
jump Json.421 Json.426 Json.138;
else
let Json.423 : {List U8, List U8} = Struct {Json.141, Json.140};
ret Json.423;
else
let Json.435 : {List U8, List U8} = Struct {Json.141, Json.140};
ret Json.435;
in
jump Json.421 Json.452 Json.453;
procedure Json.143 (Json.432):
let Json.433 : List U8 = StructAtIndex 1 Json.432;
inc Json.433;
dec Json.432;
ret Json.433;
procedure Json.2 ():
let Json.396 : {} = Struct {};
ret Json.396;
procedure Json.22 (Json.137, Json.138):
let Json.440 : List U8 = Array [];
let Json.420 : {List U8, List U8} = Struct {Json.137, Json.440};
let Json.419 : {List U8, List U8} = CallByName Json.139 Json.420 Json.138;
ret Json.419;
procedure Json.283 (Json.284):
let Json.442 : U8 = 34i64;
let Json.441 : Int1 = CallByName Bool.7 Json.284 Json.442;
ret Json.441;
procedure Json.293 (Json.294, Json.399):
let Json.400 : {List U8, [C {}, C Str]} = CallByName Json.40 Json.294;
ret Json.400;
procedure Json.40 (Json.276):
let Json.446 : U64 = 1i64;
inc Json.276;
let Json.445 : {List U8, List U8} = CallByName List.52 Json.276 Json.446;
let Json.277 : List U8 = StructAtIndex 0 Json.445;
inc Json.277;
let Json.279 : List U8 = StructAtIndex 1 Json.445;
inc Json.279;
dec Json.445;
let Json.444 : U8 = 34i64;
let Json.443 : List U8 = Array [Json.444];
let Json.404 : Int1 = CallByName Bool.11 Json.277 Json.443;
dec Json.443;
dec Json.277;
if Json.404 then
dec Json.276;
let Json.417 : {} = Struct {};
let Json.416 : {List U8, List U8} = CallByName Json.22 Json.279 Json.417;
let Json.282 : List U8 = StructAtIndex 0 Json.416;
inc Json.282;
let Json.281 : List U8 = StructAtIndex 1 Json.416;
inc Json.281;
dec Json.416;
let Json.405 : [C {U64, U8}, C Str] = CallByName Str.9 Json.281;
let Json.413 : U8 = 1i64;
let Json.414 : U8 = GetTagId Json.405;
let Json.415 : Int1 = lowlevel Eq Json.413 Json.414;
if Json.415 then
let Json.285 : Str = UnionAtIndex (Id 1) (Index 0) Json.405;
inc Json.285;
dec Json.405;
let Json.409 : U64 = 1i64;
let Json.408 : {List U8, List U8} = CallByName List.52 Json.282 Json.409;
let Json.287 : List U8 = StructAtIndex 1 Json.408;
inc Json.287;
dec Json.408;
let Json.407 : [C {}, C Str] = TagId(1) Json.285;
let Json.406 : {List U8, [C {}, C Str]} = Struct {Json.287, Json.407};
ret Json.406;
else
dec Json.405;
let Json.412 : {} = Struct {};
let Json.411 : [C {}, C Str] = TagId(0) Json.412;
let Json.410 : {List U8, [C {}, C Str]} = Struct {Json.282, Json.411};
ret Json.410;
else
dec Json.279;
let Json.403 : {} = Struct {};
let Json.402 : [C {}, C Str] = TagId(0) Json.403;
let Json.401 : {List U8, [C {}, C Str]} = Struct {Json.276, Json.402};
ret Json.401;
procedure Json.41 ():
let Json.398 : {} = Struct {};
let Json.397 : {} = CallByName Decode.23 Json.398;
ret Json.397;
procedure List.2 (List.95, List.96):
let List.530 : U64 = CallByName List.6 List.95;
let List.526 : Int1 = CallByName Num.22 List.96 List.530;
if List.526 then
let List.528 : U8 = CallByName List.66 List.95 List.96;
let List.527 : [C {}, C U8] = TagId(1) List.528;
ret List.527;
else
let List.525 : {} = Struct {};
let List.524 : [C {}, C U8] = TagId(0) List.525;
ret List.524;
procedure List.4 (List.106, List.107):
let List.514 : U64 = 1i64;
let List.512 : List U8 = CallByName List.70 List.106 List.514;
let List.511 : List U8 = CallByName List.71 List.512 List.107;
ret List.511;
procedure List.49 (List.366, List.367):
let List.486 : U64 = StructAtIndex 0 List.367;
let List.487 : U64 = 0i64;
let List.484 : Int1 = CallByName Bool.11 List.486 List.487;
if List.484 then
dec List.366;
let List.485 : List U8 = Array [];
ret List.485;
else
let List.481 : U64 = StructAtIndex 1 List.367;
let List.482 : U64 = StructAtIndex 0 List.367;
let List.480 : List U8 = CallByName List.72 List.366 List.481 List.482;
ret List.480;
procedure List.52 (List.381, List.382):
let List.383 : U64 = CallByName List.6 List.381;
joinpoint List.509 List.384:
let List.507 : U64 = 0i64;
let List.506 : {U64, U64} = Struct {List.384, List.507};
inc List.381;
let List.385 : List U8 = CallByName List.49 List.381 List.506;
let List.505 : U64 = CallByName Num.20 List.383 List.384;
let List.504 : {U64, U64} = Struct {List.505, List.384};
let List.386 : List U8 = CallByName List.49 List.381 List.504;
let List.503 : {List U8, List U8} = Struct {List.385, List.386};
ret List.503;
in
let List.510 : Int1 = CallByName Num.24 List.383 List.382;
if List.510 then
jump List.509 List.382;
else
jump List.509 List.383;
procedure List.6 (#Attr.2):
let List.550 : U64 = lowlevel ListLen #Attr.2;
ret List.550;
procedure List.66 (#Attr.2, #Attr.3):
let List.529 : U8 = lowlevel ListGetUnsafe #Attr.2 #Attr.3;
ret List.529;
procedure List.70 (#Attr.2, #Attr.3):
let List.515 : List U8 = lowlevel ListReserve #Attr.2 #Attr.3;
ret List.515;
procedure List.71 (#Attr.2, #Attr.3):
let List.513 : List U8 = lowlevel ListAppendUnsafe #Attr.2 #Attr.3;
ret List.513;
procedure List.72 (#Attr.2, #Attr.3, #Attr.4):
let List.483 : List U8 = lowlevel ListSublist #Attr.2 #Attr.3 #Attr.4;
ret List.483;
procedure List.9 (List.283):
let List.523 : U64 = 0i64;
let List.516 : [C {}, C U8] = CallByName List.2 List.283 List.523;
let List.520 : U8 = 1i64;
let List.521 : U8 = GetTagId List.516;
let List.522 : Int1 = lowlevel Eq List.520 List.521;
if List.522 then
let List.284 : U8 = UnionAtIndex (Id 1) (Index 0) List.516;
let List.517 : [C {}, C U8] = TagId(1) List.284;
ret List.517;
else
let List.519 : {} = Struct {};
let List.518 : [C {}, C U8] = TagId(0) List.519;
ret List.518;
procedure Num.20 (#Attr.2, #Attr.3):
let Num.258 : U64 = lowlevel NumSub #Attr.2 #Attr.3;
ret Num.258;
procedure Num.22 (#Attr.2, #Attr.3):
let Num.262 : Int1 = lowlevel NumLt #Attr.2 #Attr.3;
ret Num.262;
procedure Num.24 (#Attr.2, #Attr.3):
let Num.261 : Int1 = lowlevel NumGt #Attr.2 #Attr.3;
ret Num.261;
procedure Str.12 (#Attr.2):
let Str.274 : List U8 = lowlevel StrToUtf8 #Attr.2;
ret Str.274;
procedure Str.27 (Str.96):
let Str.265 : [C {}, C I64] = CallByName Str.69 Str.96;
ret Str.265;
procedure Str.47 (#Attr.2):
let Str.273 : {I64, U8} = lowlevel StrToNum #Attr.2;
ret Str.273;
procedure Str.48 (#Attr.2, #Attr.3, #Attr.4):
let Str.288 : {U64, Str, Int1, U8} = lowlevel StrFromUtf8Range #Attr.2 #Attr.3 #Attr.4;
ret Str.288;
procedure Str.69 (Str.231):
let Str.232 : {I64, U8} = CallByName Str.47 Str.231;
let Str.271 : U8 = StructAtIndex 1 Str.232;
let Str.272 : U8 = 0i64;
let Str.268 : Int1 = CallByName Bool.11 Str.271 Str.272;
if Str.268 then
let Str.270 : I64 = StructAtIndex 0 Str.232;
let Str.269 : [C {}, C I64] = TagId(1) Str.270;
ret Str.269;
else
let Str.267 : {} = Struct {};
let Str.266 : [C {}, C I64] = TagId(0) Str.267;
ret Str.266;
procedure Str.9 (Str.76):
let Str.286 : U64 = 0i64;
let Str.287 : U64 = CallByName List.6 Str.76;
let Str.77 : {U64, Str, Int1, U8} = CallByName Str.48 Str.76 Str.286 Str.287;
let Str.283 : Int1 = StructAtIndex 2 Str.77;
if Str.283 then
let Str.285 : Str = StructAtIndex 1 Str.77;
inc Str.285;
dec Str.77;
let Str.284 : [C {U64, U8}, C Str] = TagId(1) Str.285;
ret Str.284;
else
let Str.281 : U8 = StructAtIndex 3 Str.77;
let Str.282 : U64 = StructAtIndex 0 Str.77;
dec Str.77;
let Str.280 : {U64, U8} = Struct {Str.282, Str.281};
let Str.279 : [C {U64, U8}, C Str] = TagId(0) Str.280;
ret Str.279;
procedure Test.0 ():
let Test.37 : Str = "-1234";
let Test.35 : List U8 = CallByName Str.12 Test.37;
let Test.36 : {} = CallByName Json.2;
let Test.34 : {List U8, [C {}, C Str]} = CallByName Decode.25 Test.35 Test.36;
let Test.2 : List U8 = StructAtIndex 0 Test.34;
inc Test.2;
let Test.1 : [C {}, C Str] = StructAtIndex 1 Test.34;
inc Test.1;
dec Test.34;
let Test.31 : U8 = 1i64;
let Test.32 : U8 = GetTagId Test.1;
let Test.33 : Int1 = lowlevel Eq Test.31 Test.32;
if Test.33 then
let Test.3 : Str = UnionAtIndex (Id 1) (Index 0) Test.1;
inc Test.3;
dec Test.1;
let Test.19 : [C {}, C I64] = CallByName Str.27 Test.3;
dec Test.3;
let Test.25 : U8 = 1i64;
let Test.26 : U8 = GetTagId Test.19;
let Test.27 : Int1 = lowlevel Eq Test.25 Test.26;
if Test.27 then
let Test.4 : I64 = UnionAtIndex (Id 1) (Index 0) Test.19;
let Test.21 : {List U8, I64} = Struct {Test.2, Test.4};
let Test.20 : [C Str, C {List U8, I64}] = TagId(1) Test.21;
ret Test.20;
else
dec Test.2;
let Test.24 : Str = "not a number";
let Test.22 : [C Str, C {List U8, I64}] = TagId(0) Test.24;
ret Test.22;
else
dec Test.1;
dec Test.2;
let Test.30 : Str = "not a number";
let Test.28 : [C Str, C {List U8, I64}] = TagId(0) Test.30;
ret Test.28;
procedure Test.12 ():
let Test.10 : [C Str, C {List U8, I64}] = CallByName Test.0;
let Test.17 : List U8 = Array [];
let Test.18 : I64 = -1234i64;
let Test.16 : {List U8, I64} = Struct {Test.17, Test.18};
let Test.15 : [C Str, C {List U8, I64}] = TagId(1) Test.16;
inc Test.10;
let Test.14 : Int1 = CallByName Bool.11 Test.10 Test.15;
expect Test.14;
let Test.13 : {} = Struct {};
ret Test.13;

View File

@ -2448,3 +2448,30 @@ fn function_specialization_information_in_lambda_set_thunk_independent_defs() {
"###
)
}
#[mono_test(mode = "test")]
fn issue_4772_weakened_monomorphic_destructure() {
indoc!(
r###"
interface Test exposes [] imports [Json]
getNumber =
{ result, rest } = Decode.fromBytesPartial (Str.toUtf8 "-1234") Json.fromUtf8
when result is
Ok val ->
when Str.toI64 val is
Ok number ->
Ok {val : number, input : rest}
Err InvalidNumStr ->
Err (ParsingFailure "not a number")
Err _ ->
Err (ParsingFailure "not a number")
expect
result = getNumber
result == Ok {val : -1234i64, input : []}
"###
)
}