Newtype destructures test for record that decay into their only arg

This commit is contained in:
Ayaz Hafiz 2022-07-21 15:03:18 -04:00
parent 929a00e73d
commit f3722659fc
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
2 changed files with 26 additions and 2 deletions

View file

@ -985,9 +985,13 @@ fn needs_tests(pattern: &Pattern) -> bool {
// read the appropriate argument in the struct when constructing the decision tree. // read the appropriate argument in the struct when constructing the decision tree.
arguments.len() != 1 arguments.len() != 1
} }
RecordDestructure(arguments, _) => {
// Same logic as for newtype destructures - records with one argument decay into their
// argument.
arguments.len() != 1
}
RecordDestructure(_, _) AppliedTag { .. }
| AppliedTag { .. }
| OpaqueUnwrap { .. } | OpaqueUnwrap { .. }
| BitLiteral { .. } | BitLiteral { .. }
| EnumLiteral { .. } | EnumLiteral { .. }

View file

@ -1825,3 +1825,23 @@ fn issue_3560_nested_tag_constructor_is_newtype() {
(u8, u8) (u8, u8)
) )
} }
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn issue_3560_nested_tag_constructor_is_record_newtype() {
assert_evals_to!(
indoc!(
r#"
f : _ -> u8
f = \t ->
when t is
{wrapper: (Payload it)} -> it
{wrapper: (AlternatePayload it)} -> it
{a: f {wrapper: (Payload 15u8)}, b: f {wrapper: (AlternatePayload 31u8)}}
"#
),
(15, 31),
(u8, u8)
)
}