Merge branch 'trunk' into incompatible_type_param

This commit is contained in:
Folkert de Vries 2021-07-04 01:09:04 +02:00 committed by GitHub
commit b35eb85e03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 10 deletions

View file

@ -4131,17 +4131,17 @@ fn convert_tag_union<'a>(
hole,
),
ByteUnion(tag_names) => {
let tag_id = tag_names
.iter()
.position(|key| key == &tag_name)
.expect("tag must be in its own type");
let opt_tag_id = tag_names.iter().position(|key| key == &tag_name);
Stmt::Let(
assigned,
Expr::Literal(Literal::Byte(tag_id as u8)),
Layout::Builtin(Builtin::Int8),
hole,
)
match opt_tag_id {
Some(tag_id) => Stmt::Let(
assigned,
Expr::Literal(Literal::Byte(tag_id as u8)),
Layout::Builtin(Builtin::Int8),
hole,
),
None => Stmt::RuntimeError("tag must be in its own type"),
}
}
Newtype {

View file

@ -1033,3 +1033,20 @@ fn applied_tag_function_linked_list() {
i64
);
}
#[test]
#[should_panic(expected = "")]
fn tag_must_be_its_own_type() {
assert_evals_to!(
indoc!(
r#"
z : [ A, B, C ]
z = Z
z
"#
),
1,
i64
);
}