From 8deb377d30128eebd96090725b3a63705b904aa0 Mon Sep 17 00:00:00 2001 From: Eric Correia Date: Sat, 3 Jul 2021 12:06:48 -0400 Subject: [PATCH 1/2] tag must be its own type fix --- compiler/mono/src/ir.rs | 21 +++++++++++---------- compiler/test_gen/src/gen_tags.rs | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 94877e4ad0..9729d7b27d 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -4126,17 +4126,18 @@ 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); + // .expect("tag must be in its own type"); - 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 { diff --git a/compiler/test_gen/src/gen_tags.rs b/compiler/test_gen/src/gen_tags.rs index 776c06ff07..cfd11b807f 100644 --- a/compiler/test_gen/src/gen_tags.rs +++ b/compiler/test_gen/src/gen_tags.rs @@ -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 + ); +} From aa123635fa23c022f24f8b285ee04efc88df4e27 Mon Sep 17 00:00:00 2001 From: Eric Correia Date: Sat, 3 Jul 2021 12:08:42 -0400 Subject: [PATCH 2/2] remove comment --- compiler/mono/src/ir.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 9729d7b27d..87080476cb 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -4127,7 +4127,6 @@ fn convert_tag_union<'a>( ), ByteUnion(tag_names) => { let opt_tag_id = tag_names.iter().position(|key| key == &tag_name); - // .expect("tag must be in its own type"); match opt_tag_id { Some(tag_id) => Stmt::Let(