diff --git a/compiler/builtins/src/std.rs b/compiler/builtins/src/std.rs index 70f120044f..a4824de997 100644 --- a/compiler/builtins/src/std.rs +++ b/compiler/builtins/src/std.rs @@ -371,9 +371,22 @@ pub fn types() -> MutMap { // List module - // #getUnsafe : List elem, Int -> elem + // get : List elem, Int -> Result elem [ IndexOutOfBounds ]* + let index_out_of_bounds = SolvedType::TagUnion( + vec![(TagName::Global("IndexOutOfBounds".into()), vec![])], + Box::new(SolvedType::Wildcard), + ); + add_type( - Symbol::LIST_GET_UNSAFE, + Symbol::LIST_GET, + SolvedType::Func( + vec![list_type(flex(TVAR1)), int_type()], + Box::new(result_type(flex(TVAR1), index_out_of_bounds)), + ), + ); + + add_type( + Symbol::LIST_GET_UNSAFE, // TODO remove this once we can code gen Result SolvedType::Func( vec![list_type(flex(TVAR1)), int_type()], Box::new(flex(TVAR1)), diff --git a/compiler/gen/tests/gen_builtins.rs b/compiler/gen/tests/gen_builtins.rs index 747fe99813..d9d2174e44 100644 --- a/compiler/gen/tests/gen_builtins.rs +++ b/compiler/gen/tests/gen_builtins.rs @@ -301,11 +301,6 @@ mod gen_builtins { assert_evals_to!("List.isEmpty []", true, bool); } - // #[test] - // fn get_0_int_list() { - // assert_evals_to!("List.get [ 12, 9, 6, 3 ] 0", (1, 12), (u64, i64)); - // } - #[test] fn head_int_list() { assert_evals_to!("List.first [ 12, 9, 6, 3 ]", (1, 12), (u64, i64)); diff --git a/compiler/uniq/src/sharing.rs b/compiler/uniq/src/sharing.rs index 6d9aaa1826..e81a621c71 100644 --- a/compiler/uniq/src/sharing.rs +++ b/compiler/uniq/src/sharing.rs @@ -495,7 +495,13 @@ impl FieldAccess { } pub fn list_seen() -> Self { - Self::default() + use Mark::*; + use Usage::*; + + let mut result = Self::default(); + result.fields.insert(LIST_ELEM.into(), Simple(Seen)); + + result } pub fn list_update() -> Self {