tag must be its own type fix

This commit is contained in:
Eric Correia 2021-07-03 12:06:48 -04:00
parent 28520b2cf4
commit 8deb377d30
2 changed files with 28 additions and 10 deletions

View file

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

View file

@ -1033,3 +1033,20 @@ fn applied_tag_function_linked_list() {
i64 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
);
}