From b82baf55e74ee497b71189472a40036c3f4884a2 Mon Sep 17 00:00:00 2001 From: Dimitar Apostolov Date: Sun, 20 Sep 2020 14:11:34 +0200 Subject: [PATCH] Add types for Str.startsWith --- compiler/builtins/src/std.rs | 6 ++++++ compiler/builtins/src/unique.rs | 6 ++++++ compiler/solve/tests/solve_expr.rs | 12 ++++++++++++ 3 files changed, 24 insertions(+) diff --git a/compiler/builtins/src/std.rs b/compiler/builtins/src/std.rs index 55a8a80bc5..6becd5d38c 100644 --- a/compiler/builtins/src/std.rs +++ b/compiler/builtins/src/std.rs @@ -505,6 +505,12 @@ pub fn types() -> MutMap { top_level_function(vec![str_type()], Box::new(bool_type())), ); + // startsWith : Str, Str -> Bool + add_type( + Symbol::STR_STARTS_WITH, + SolvedType::Func(vec![str_type(), str_type()], Box::new(bool_type())), + ); + // List module // get : List elem, Int -> Result elem [ OutOfBounds ]* diff --git a/compiler/builtins/src/unique.rs b/compiler/builtins/src/unique.rs index 17db447b05..b36ab7a247 100644 --- a/compiler/builtins/src/unique.rs +++ b/compiler/builtins/src/unique.rs @@ -1134,6 +1134,12 @@ pub fn types() -> MutMap { unique_function(vec![str_type(star1), str_type(star2)], str_type(star3)) }); + // Str.startsWith : Attr * Str, Attr * Str -> Attr * Bool + add_type(Symbol::STR_STARTS_WITH, { + let_tvars! { star1, star2, star3 }; + unique_function(vec![str_type(star1), str_type(star2)], bool_type(star3)) + }); + // Result module // map : Attr * (Result (Attr a e)) diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 9ba40a6893..0c8fa22f89 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -192,6 +192,18 @@ mod solve_expr { ); } + #[test] + fn string_starts_with() { + infer_eq_without_problem( + indoc!( + r#" + Str.startsWith + "# + ), + "Str, Str -> Bool", + ); + } + // #[test] // fn block_string_literal() { // infer_eq(