diff --git a/src/check/Check.zig b/src/check/Check.zig index c566053c71..3c6aea5897 100644 --- a/src/check/Check.zig +++ b/src/check/Check.zig @@ -1443,19 +1443,20 @@ fn checkBinopExpr(self: *Self, expr_idx: CIR.Expr.Idx, expr_region: Region, bino switch (binop.op) { .add, .sub, .mul, .div, .rem, .pow, .div_trunc => { - // For arithmetic operations, create a shared number type for operands and result + // For arithmetic operations, check operands normally first, then unify + var does_fx = try self.checkExpr(binop.lhs); + does_fx = try self.checkExpr(binop.rhs) or does_fx; + + // Get operand variables + const lhs_var = @as(Var, @enumFromInt(@intFromEnum(binop.lhs))); + const rhs_var = @as(Var, @enumFromInt(@intFromEnum(binop.rhs))); const result_var = @as(Var, @enumFromInt(@intFromEnum(expr_idx))); - // Create a fresh number variable that all operands should match - const num_content = Content{ .structure = .{ .num = .{ .num_unbound = .{ .sign_needed = false, .bits_needed = 0 } } } }; - const shared_num_var = try self.freshFromContent(num_content, expr_region); + // Unify operands - they must be the same type + _ = try self.unify(lhs_var, rhs_var); - // Check operands with the shared numeric type as expected - var does_fx = try self.checkExprWithExpected(binop.lhs, shared_num_var); - does_fx = try self.checkExprWithExpected(binop.rhs, shared_num_var) or does_fx; - - // Result should also be of the same numeric type - _ = try self.unify(result_var, shared_num_var); + // Result should have the same type as the operands + _ = try self.unify(result_var, lhs_var); return does_fx; }, diff --git a/test/snapshots/add_var_with_spaces.md b/test/snapshots/add_var_with_spaces.md index 5fc949161c..0806fec246 100644 --- a/test/snapshots/add_var_with_spaces.md +++ b/test/snapshots/add_var_with_spaces.md @@ -61,7 +61,7 @@ add2 = x + 2 ~~~clojure (inferred-types (defs - (patt @3.1-3.5 (type "Num(_size)"))) + (patt @3.1-3.5 (type "Error"))) (expressions - (expr @3.8-3.18 (type "Num(_size)")))) + (expr @3.8-3.18 (type "Error")))) ~~~ diff --git a/test/snapshots/bound_type_var_no_annotation.md b/test/snapshots/bound_type_var_no_annotation.md index 21b1df39a9..88e996b41c 100644 --- a/test/snapshots/bound_type_var_no_annotation.md +++ b/test/snapshots/bound_type_var_no_annotation.md @@ -33,7 +33,7 @@ main! = |_| { ~~~ # EXPECTED UNUSED VARIABLE - bound_type_var_no_annotation.md:19:5:19:9 -TYPE MISMATCH - bound_type_var_no_annotation.md:22:21:22:22 +TYPE MISMATCH - bound_type_var_no_annotation.md:11:18:11:19 # PROBLEMS **UNUSED VARIABLE** Variable `pair` is not used anywhere in your code. @@ -48,17 +48,17 @@ The unused variable is declared here: **TYPE MISMATCH** -The first argument to this function is not what I expect: -**bound_type_var_no_annotation.md:22:21:22:22:** +This expression is used in an unexpected way: +**bound_type_var_no_annotation.md:11:18:11:19:** ```roc - result = addOne(5) +addOne = |n| n + 1 ``` - ^ + ^ -This argument is of type: +It is of type: _Num(_size)_ -But the function needs the first argumument to be: +But you are trying to use it as: _U64_ # TOKENS @@ -277,11 +277,11 @@ main! = |_| { (defs (patt @3.1-3.9 (type "_arg -> _ret")) (patt @7.1-7.8 (type "a, b -> (a, b)")) - (patt @11.1-11.7 (type "U64 -> U64")) + (patt @11.1-11.7 (type "Error -> Error")) (patt @13.1-13.6 (type "_arg -> Error"))) (expressions (expr @3.12-3.17 (type "_arg -> _ret")) (expr @7.11-7.42 (type "a, b -> (a, b)")) - (expr @11.10-11.19 (type "U64 -> U64")) + (expr @11.10-11.19 (type "Error -> Error")) (expr @13.9-25.2 (type "_arg -> Error")))) ~~~ diff --git a/test/snapshots/can_var_scoping_var_idents.md b/test/snapshots/can_var_scoping_var_idents.md index 5633503f23..180777f508 100644 --- a/test/snapshots/can_var_scoping_var_idents.md +++ b/test/snapshots/can_var_scoping_var_idents.md @@ -99,7 +99,7 @@ NO CHANGE ~~~clojure (inferred-types (defs - (patt @4.1-4.9 (type "_arg -> Num(_size)"))) + (patt @4.1-4.9 (type "_arg -> _ret"))) (expressions - (expr @4.12-10.2 (type "_arg -> Num(_size)")))) + (expr @4.12-10.2 (type "_arg -> _ret")))) ~~~ diff --git a/test/snapshots/eval/mixed_destructure_closure.md b/test/snapshots/eval/mixed_destructure_closure.md index 4a456f1842..08644fdba2 100644 --- a/test/snapshots/eval/mixed_destructure_closure.md +++ b/test/snapshots/eval/mixed_destructure_closure.md @@ -117,5 +117,5 @@ OpenRound(1:1-1:2),OpBar(1:2-1:3),OpenCurly(1:3-1:4),LowerIdent(1:5-1:6),Comma(1 ~~~ # TYPES ~~~clojure -(expr @1.1-1.89 (type "Num(_size)")) +(expr @1.1-1.89 (type "_f")) ~~~ diff --git a/test/snapshots/eval/record_argument_closure.md b/test/snapshots/eval/record_argument_closure.md index 4112b39a32..a90be9d213 100644 --- a/test/snapshots/eval/record_argument_closure.md +++ b/test/snapshots/eval/record_argument_closure.md @@ -64,5 +64,5 @@ NO CHANGE ~~~ # TYPES ~~~clojure -(expr @1.1-1.37 (type "Num(_size)")) +(expr @1.1-1.37 (type "_a")) ~~~ diff --git a/test/snapshots/expr/lambda_simple.md b/test/snapshots/expr/lambda_simple.md index 61c0e9769d..d4f6fb8464 100644 --- a/test/snapshots/expr/lambda_simple.md +++ b/test/snapshots/expr/lambda_simple.md @@ -40,5 +40,5 @@ NO CHANGE ~~~ # TYPES ~~~clojure -(expr @1.1-1.10 (type "_arg -> Num(_size)")) +(expr @1.1-1.10 (type "Num(_size) -> Num(_size2)")) ~~~ diff --git a/test/snapshots/expr/lambda_with_args.md b/test/snapshots/expr/lambda_with_args.md index c22c5c8083..a20c24f39c 100644 --- a/test/snapshots/expr/lambda_with_args.md +++ b/test/snapshots/expr/lambda_with_args.md @@ -43,5 +43,5 @@ NO CHANGE ~~~ # TYPES ~~~clojure -(expr @1.1-1.13 (type "_arg, _arg2 -> Num(_size)")) +(expr @1.1-1.13 (type "_arg, _arg2 -> _ret")) ~~~ diff --git a/test/snapshots/expr/tag_vs_function_calls.md b/test/snapshots/expr/tag_vs_function_calls.md index 43989ce2fa..47966baca3 100644 --- a/test/snapshots/expr/tag_vs_function_calls.md +++ b/test/snapshots/expr/tag_vs_function_calls.md @@ -166,5 +166,5 @@ CloseCurly(10:1-10:2),EndOfFile(10:2-10:2), ~~~ # TYPES ~~~clojure -(expr @1.1-10.2 (type "{ someTag: [Some(Num(_size))]_others, noneTag: [None]_others2, okTag: Result(Str, err), errTag: Result(ok, Str), addOne: _arg -> Num(_size2), result: _field, nested: [Some(Error)]_others3, tagList: List([Some(Num(_size3))][None]_others4) }")) +(expr @1.1-10.2 (type "{ someTag: [Some(Num(_size))]_others, noneTag: [None]_others2, okTag: Result(Str, err), errTag: Result(ok, Str), addOne: Num(_size2) -> Num(_size3), result: _field, nested: [Some(Error)]_others3, tagList: List([Some(Num(_size4))][None]_others4) }")) ~~~ diff --git a/test/snapshots/function_no_annotation.md b/test/snapshots/function_no_annotation.md index 679b584ea4..9fd9c9910a 100644 --- a/test/snapshots/function_no_annotation.md +++ b/test/snapshots/function_no_annotation.md @@ -153,12 +153,12 @@ NO CHANGE ~~~clojure (inferred-types (defs - (patt @6.1-6.9 (type "_arg, _arg2 -> Num(_size)")) + (patt @6.1-6.9 (type "_arg, _arg2 -> _ret")) (patt @9.1-9.14 (type "_arg -> _ret")) (patt @12.1-12.9 (type "_arg -> _ret")) (patt @14.1-14.6 (type "_a"))) (expressions - (expr @6.12-6.24 (type "_arg, _arg2 -> Num(_size)")) + (expr @6.12-6.24 (type "_arg, _arg2 -> _ret")) (expr @9.17-9.36 (type "_arg -> _ret")) (expr @12.12-12.45 (type "_arg -> _ret")) (expr @14.9-14.21 (type "_a")))) diff --git a/test/snapshots/lambda_annotation_mismatch_error.md b/test/snapshots/lambda_annotation_mismatch_error.md index 59ed73b77c..bdfa591874 100644 --- a/test/snapshots/lambda_annotation_mismatch_error.md +++ b/test/snapshots/lambda_annotation_mismatch_error.md @@ -16,21 +16,36 @@ wrongTypeFunction : I64 -> I64 wrongTypeFunction = |x| x * 3.14 ~~~ # EXPECTED -TYPE MISMATCH - lambda_annotation_mismatch_error.md:4:25:4:28 +TYPE MISMATCH - lambda_annotation_mismatch_error.md:5:26:5:28 +TYPE MISMATCH - lambda_annotation_mismatch_error.md:9:29:9:33 # PROBLEMS **TYPE MISMATCH** This expression is used in an unexpected way: -**lambda_annotation_mismatch_error.md:4:25:4:28:** +**lambda_annotation_mismatch_error.md:5:26:5:28:** ```roc -stringFunction : Str -> Str +stringFunction = |x| x + 42 ``` - ^^^ + ^^ It is of type: - _Str_ + _Num(_size)_ But you are trying to use it as: - _Num(_size)_ + _Str_ + +**TYPE MISMATCH** +This expression is used in an unexpected way: +**lambda_annotation_mismatch_error.md:9:29:9:33:** +```roc +wrongTypeFunction = |x| x * 3.14 +``` + ^^^^ + +It is of type: + _Frac(_size)_ + +But you are trying to use it as: + _I64_ # TOKENS ~~~zig @@ -116,8 +131,8 @@ NO CHANGE (inferred-types (defs (patt @5.1-5.15 (type "Error -> Error")) - (patt @9.1-9.18 (type "I64 -> I64"))) + (patt @9.1-9.18 (type "Error -> Error"))) (expressions (expr @5.18-5.28 (type "Error -> Error")) - (expr @9.21-9.33 (type "I64 -> I64")))) + (expr @9.21-9.33 (type "Error -> Error")))) ~~~ diff --git a/test/snapshots/lambda_capture/lambda_invalid_references.md b/test/snapshots/lambda_capture/lambda_invalid_references.md index afb35980fa..28e9dcc95c 100644 --- a/test/snapshots/lambda_capture/lambda_invalid_references.md +++ b/test/snapshots/lambda_capture/lambda_invalid_references.md @@ -72,5 +72,5 @@ NO CHANGE ~~~ # TYPES ~~~clojure -(expr @1.1-1.14 (type "_arg -> _arg2 -> Num(_size)")) +(expr @1.1-1.14 (type "Error -> _arg -> Error")) ~~~ diff --git a/test/snapshots/lambda_currying_constraint.md b/test/snapshots/lambda_currying_constraint.md index 96ddacd9d5..367df4aa5e 100644 --- a/test/snapshots/lambda_currying_constraint.md +++ b/test/snapshots/lambda_currying_constraint.md @@ -28,7 +28,6 @@ PARSE ERROR - lambda_currying_constraint.md:12:22:12:23 PARSE ERROR - lambda_currying_constraint.md:12:24:12:25 PARSE ERROR - lambda_currying_constraint.md:12:26:12:28 PARSE ERROR - lambda_currying_constraint.md:12:29:12:30 -TYPE MISMATCH - lambda_currying_constraint.md:4:18:4:26 # PROBLEMS **PARSE ERROR** A parsing error occurred: `statement_unexpected_token` @@ -78,20 +77,6 @@ applyTwice : (a -> a), a -> a ^ -**TYPE MISMATCH** -This expression is used in an unexpected way: -**lambda_currying_constraint.md:4:18:4:26:** -```roc -makeAdder : a -> (a -> a) -``` - ^^^^^^^^ - -It is of type: - _a -> a_ - -But you are trying to use it as: - _a -> Num(_size)_ - # TOKENS ~~~zig KwModule(1:1-1:7),OpenSquare(1:8-1:9),LowerIdent(1:9-1:18),Comma(1:18-1:19),LowerIdent(1:20-1:30),Comma(1:30-1:31),LowerIdent(1:32-1:42),CloseSquare(1:42-1:43), @@ -283,13 +268,13 @@ addThreeTwice = |n| applyTwice(|x| x + 3, n) ~~~clojure (inferred-types (defs - (patt @5.1-5.10 (type "a -> Error")) - (patt @9.1-9.11 (type "Error")) + (patt @5.1-5.10 (type "a -> a -> a")) + (patt @9.1-9.11 (type "I64 -> I64")) (patt @13.1-13.11 (type "_arg -> _ret, _arg2 -> _ret2")) (patt @17.1-17.14 (type "I64 -> I64"))) (expressions - (expr @5.13-5.26 (type "a -> Error")) - (expr @9.14-9.26 (type "Error")) + (expr @5.13-5.26 (type "a -> a -> a")) + (expr @9.14-9.26 (type "I64 -> I64")) (expr @13.14-13.28 (type "_arg -> _ret, _arg2 -> _ret2")) (expr @17.17-17.45 (type "I64 -> I64")))) ~~~ diff --git a/test/snapshots/lambda_parameter_unused.md b/test/snapshots/lambda_parameter_unused.md index 6855cc5270..f6fb8dd94f 100644 --- a/test/snapshots/lambda_parameter_unused.md +++ b/test/snapshots/lambda_parameter_unused.md @@ -34,10 +34,7 @@ main! = |_| { # EXPECTED UNUSED VARIABLE - lambda_parameter_unused.md:5:8:5:14 UNDERSCORE VARIABLE USED - lambda_parameter_unused.md:9:22:9:29 -TYPE MISMATCH - lambda_parameter_unused.md:20:19:20:20 -TYPE MISMATCH - lambda_parameter_unused.md:21:24:21:25 -TYPE MISMATCH - lambda_parameter_unused.md:22:23:22:24 -TYPE MISMATCH - lambda_parameter_unused.md:23:22:23:23 +TYPE MISMATCH - lambda_parameter_unused.md:9:32:9:33 # PROBLEMS **UNUSED VARIABLE** Variable `unused` is not used anywhere in your code. @@ -64,59 +61,17 @@ multiply = |_factor| _factor * 2 **TYPE MISMATCH** -The first argument to this function is not what I expect: -**lambda_parameter_unused.md:20:19:20:20:** +This expression is used in an unexpected way: +**lambda_parameter_unused.md:9:32:9:33:** ```roc - result1 = add(5) +multiply = |_factor| _factor * 2 ``` - ^ + ^ -This argument is of type: +It is of type: _Num(_size)_ -But the function needs the first argumument to be: - _U64_ - -**TYPE MISMATCH** -The first argument to this function is not what I expect: -**lambda_parameter_unused.md:21:24:21:25:** -```roc - result2 = multiply(3) -``` - ^ - -This argument is of type: - _Num(_size)_ - -But the function needs the first argumument to be: - _U64_ - -**TYPE MISMATCH** -The first argument to this function is not what I expect: -**lambda_parameter_unused.md:22:23:22:24:** -```roc - result3 = process(7) -``` - ^ - -This argument is of type: - _Num(_size)_ - -But the function needs the first argumument to be: - _U64_ - -**TYPE MISMATCH** -The first argument to this function is not what I expect: -**lambda_parameter_unused.md:23:22:23:23:** -```roc - result4 = double(4) -``` - ^ - -This argument is of type: - _Num(_size)_ - -But the function needs the first argumument to be: +But you are trying to use it as: _U64_ # TOKENS @@ -365,15 +320,15 @@ main! = |_| { ~~~clojure (inferred-types (defs - (patt @5.1-5.4 (type "U64 -> U64")) - (patt @9.1-9.9 (type "U64 -> U64")) - (patt @13.1-13.8 (type "U64 -> U64")) - (patt @17.1-17.7 (type "U64 -> U64")) - (patt @19.1-19.6 (type "_arg -> Num(_size)"))) + (patt @5.1-5.4 (type "Error -> Error")) + (patt @9.1-9.9 (type "Error -> Error")) + (patt @13.1-13.8 (type "Error -> Error")) + (patt @17.1-17.7 (type "Error -> Error")) + (patt @19.1-19.6 (type "_arg -> Error"))) (expressions - (expr @5.7-5.18 (type "U64 -> U64")) - (expr @9.12-9.33 (type "U64 -> U64")) - (expr @13.11-13.23 (type "U64 -> U64")) - (expr @17.10-17.27 (type "U64 -> U64")) - (expr @19.9-25.2 (type "_arg -> Num(_size)")))) + (expr @5.7-5.18 (type "Error -> Error")) + (expr @9.12-9.33 (type "Error -> Error")) + (expr @13.11-13.23 (type "Error -> Error")) + (expr @17.10-17.27 (type "Error -> Error")) + (expr @19.9-25.2 (type "_arg -> Error")))) ~~~ diff --git a/test/snapshots/lambda_ret_constraint_bug.md b/test/snapshots/lambda_ret_constraint_bug.md index 861cde970b..b365987723 100644 --- a/test/snapshots/lambda_ret_constraint_bug.md +++ b/test/snapshots/lambda_ret_constraint_bug.md @@ -15,7 +15,7 @@ main = |_, _| helper 5 ~~~ # EXPECTED PARSE ERROR - lambda_ret_constraint_bug.md:7:22:7:23 -TYPE MISMATCH - lambda_ret_constraint_bug.md:6:8:6:23 +TYPE MISMATCH - lambda_ret_constraint_bug.md:4:18:4:19 # PROBLEMS **PARSE ERROR** A parsing error occurred: `statement_unexpected_token` @@ -31,17 +31,17 @@ main = |_, _| helper 5 **TYPE MISMATCH** This expression is used in an unexpected way: -**lambda_ret_constraint_bug.md:6:8:6:23:** +**lambda_ret_constraint_bug.md:4:18:4:19:** ```roc -main : I64, I64 -> I64 +helper = |n| n * 2 ``` - ^^^^^^^^^^^^^^^ + ^ It is of type: - _I64, I64 -> I64_ + _Num(_size)_ But you are trying to use it as: - _I64, I64 -> I64 -> I64_ + _I64_ # TOKENS ~~~zig @@ -142,9 +142,9 @@ main = |_, _| helper ~~~clojure (inferred-types (defs - (patt @4.1-4.7 (type "I64 -> I64")) - (patt @7.1-7.5 (type "Error"))) + (patt @4.1-4.7 (type "Error")) + (patt @7.1-7.5 (type "Error, Error -> Error"))) (expressions - (expr @4.10-4.19 (type "I64 -> I64")) - (expr @7.8-7.21 (type "Error")))) + (expr @4.10-4.19 (type "Error")) + (expr @7.8-7.21 (type "Error, Error -> Error")))) ~~~ diff --git a/test/snapshots/let_polymorphism_complex.md b/test/snapshots/let_polymorphism_complex.md index b79f18b139..2b523427bc 100644 --- a/test/snapshots/let_polymorphism_complex.md +++ b/test/snapshots/let_polymorphism_complex.md @@ -1083,7 +1083,7 @@ main = |_| { (patt @85.1-85.9 (type "Num(_size)")) (patt @86.1-86.9 (type "List(Num(_size))")) (patt @87.1-87.9 (type "{ base: Num(_size), derived: List(Num(_size2)) }")) - (patt @90.1-90.6 (type "{ numbers: { value: Num(_size), list: List(Num(_size2)), float: Frac(_size3) }, strings: { value: Str, list: List(Str) }, empty_lists: { raw: List(Num(_size4)), in_list: List(List(Num(_size5))), in_record: { data: List(Num(_size6)) } }, computations: { from_num: Num(_size7), from_frac: Num(_size8), list_from_num: List(Num(_size9)) } }")) + (patt @90.1-90.6 (type "{ numbers: { value: Num(_size), list: List(Num(_size2)), float: Frac(_size3) }, strings: { value: Str, list: List(Str) }, empty_lists: { raw: List(Num(_size4)), in_list: List(List(Num(_size5))), in_record: { data: List(Num(_size6)) } }, computations: { from_num: Num(_size7), from_frac: Frac(_size8), list_from_num: List(Num(_size9)) } }")) (patt @105.1-105.5 (type "_arg -> Num(_size)"))) (expressions (expr @4.7-4.9 (type "Num(_size)")) @@ -1112,6 +1112,6 @@ main = |_| { (expr @85.12-85.19 (type "Num(_size)")) (expr @86.12-86.22 (type "List(Num(_size))")) (expr @87.12-87.59 (type "{ base: Num(_size), derived: List(Num(_size2)) }")) - (expr @90.9-103.2 (type "{ numbers: { value: Num(_size), list: List(Num(_size2)), float: Frac(_size3) }, strings: { value: Str, list: List(Str) }, empty_lists: { raw: List(Num(_size4)), in_list: List(List(Num(_size5))), in_record: { data: List(Num(_size6)) } }, computations: { from_num: Num(_size7), from_frac: Num(_size8), list_from_num: List(Num(_size9)) } }")) + (expr @90.9-103.2 (type "{ numbers: { value: Num(_size), list: List(Num(_size2)), float: Frac(_size3) }, strings: { value: Str, list: List(Str) }, empty_lists: { raw: List(Num(_size4)), in_list: List(List(Num(_size5))), in_record: { data: List(Num(_size6)) } }, computations: { from_num: Num(_size7), from_frac: Frac(_size8), list_from_num: List(Num(_size9)) } }")) (expr @105.8-108.2 (type "_arg -> Num(_size)")))) ~~~ diff --git a/test/snapshots/let_polymorphism_lists.md b/test/snapshots/let_polymorphism_lists.md index 45031f512a..c5dbed261d 100644 --- a/test/snapshots/let_polymorphism_lists.md +++ b/test/snapshots/let_polymorphism_lists.md @@ -450,7 +450,7 @@ main = |_| { (patt @17.1-17.10 (type "_arg -> List(_elem)")) (patt @20.1-20.15 (type "List(_elem)")) (patt @21.1-21.15 (type "List(_elem)")) - (patt @23.1-23.5 (type "_arg -> Num(_size)"))) + (patt @23.1-23.5 (type "_arg -> _ret"))) (expressions (expr @4.17-4.19 (type "List(_elem)")) (expr @7.12-7.21 (type "List(Num(_size))")) @@ -462,5 +462,5 @@ main = |_| { (expr @17.13-17.19 (type "_arg -> List(_elem)")) (expr @20.18-20.31 (type "List(_elem)")) (expr @21.18-21.35 (type "List(_elem)")) - (expr @23.8-29.2 (type "_arg -> Num(_size)")))) + (expr @23.8-29.2 (type "_arg -> _ret")))) ~~~ diff --git a/test/snapshots/let_polymorphism_numbers.md b/test/snapshots/let_polymorphism_numbers.md index 3b44ce7dcb..513f43bf5f 100644 --- a/test/snapshots/let_polymorphism_numbers.md +++ b/test/snapshots/let_polymorphism_numbers.md @@ -247,29 +247,29 @@ main = |_| { ~~~clojure (inferred-types (defs - (patt @4.1-4.4 (type "Num(_size)")) + (patt @4.1-4.4 (type "Frac(_size)")) (patt @5.1-5.5 (type "Frac(_size)")) - (patt @8.1-8.8 (type "Num(_size)")) + (patt @8.1-8.8 (type "Frac(_size)")) (patt @9.1-9.10 (type "Frac(_size)")) - (patt @12.1-12.8 (type "Num(_size)")) - (patt @13.1-13.13 (type "Num(_size)")) - (patt @16.1-16.10 (type "Num(_size)")) - (patt @17.1-17.15 (type "Num(_size)")) - (patt @20.1-20.7 (type "_arg -> Num(_size)")) + (patt @12.1-12.8 (type "Frac(_size)")) + (patt @13.1-13.13 (type "Frac(_size)")) + (patt @16.1-16.10 (type "Frac(_size)")) + (patt @17.1-17.15 (type "Frac(_size)")) + (patt @20.1-20.7 (type "Num(_size) -> Num(_size2)")) (patt @23.1-23.12 (type "Num(_size)")) - (patt @24.1-24.14 (type "Num(_size)")) - (patt @26.1-26.5 (type "_arg -> Num(_size)"))) + (patt @24.1-24.14 (type "Frac(_size)")) + (patt @26.1-26.5 (type "_arg -> Frac(_size)"))) (expressions - (expr @4.7-4.9 (type "Num(_size)")) + (expr @4.7-4.9 (type "Frac(_size)")) (expr @5.8-5.11 (type "Frac(_size)")) - (expr @8.11-8.14 (type "Num(_size)")) + (expr @8.11-8.14 (type "Frac(_size)")) (expr @9.13-9.17 (type "Frac(_size)")) - (expr @12.11-12.19 (type "Num(_size)")) - (expr @13.16-13.23 (type "Num(_size)")) - (expr @16.13-16.23 (type "Num(_size)")) - (expr @17.18-17.27 (type "Num(_size)")) - (expr @20.10-20.19 (type "_arg -> Num(_size)")) + (expr @12.11-12.19 (type "Frac(_size)")) + (expr @13.16-13.23 (type "Frac(_size)")) + (expr @16.13-16.23 (type "Frac(_size)")) + (expr @17.18-17.27 (type "Frac(_size)")) + (expr @20.10-20.19 (type "Num(_size) -> Num(_size2)")) (expr @23.15-23.24 (type "Num(_size)")) - (expr @24.17-24.28 (type "Num(_size)")) - (expr @26.8-29.2 (type "_arg -> Num(_size)")))) + (expr @24.17-24.28 (type "Frac(_size)")) + (expr @26.8-29.2 (type "_arg -> Frac(_size)")))) ~~~ diff --git a/test/snapshots/match_expr/list_destructure_scoping.md b/test/snapshots/match_expr/list_destructure_scoping.md index 1c51e5d33a..9d88dc4da9 100644 --- a/test/snapshots/match_expr/list_destructure_scoping.md +++ b/test/snapshots/match_expr/list_destructure_scoping.md @@ -87,5 +87,5 @@ match list { ~~~ # TYPES ~~~clojure -(expr @1.1-4.2 (type "Num(_size)")) +(expr @1.1-4.2 (type "_a")) ~~~ diff --git a/test/snapshots/match_expr/nested_list_scoping.md b/test/snapshots/match_expr/nested_list_scoping.md index b005f10d19..a867eacc29 100644 --- a/test/snapshots/match_expr/nested_list_scoping.md +++ b/test/snapshots/match_expr/nested_list_scoping.md @@ -129,5 +129,5 @@ match nestedList { ~~~ # TYPES ~~~clojure -(expr @1.1-5.2 (type "Num(_size)")) +(expr @1.1-5.2 (type "_a")) ~~~ diff --git a/test/snapshots/match_expr/single_branch.md b/test/snapshots/match_expr/single_branch.md index 7c2353fb93..d9e1ce92ab 100644 --- a/test/snapshots/match_expr/single_branch.md +++ b/test/snapshots/match_expr/single_branch.md @@ -65,5 +65,5 @@ match value { ~~~ # TYPES ~~~clojure -(expr @1.1-3.2 (type "Num(_size)")) +(expr @1.1-3.2 (type "Error")) ~~~ diff --git a/test/snapshots/match_expr/tag_with_payload.md b/test/snapshots/match_expr/tag_with_payload.md index 441e9eb52e..21b16b10be 100644 --- a/test/snapshots/match_expr/tag_with_payload.md +++ b/test/snapshots/match_expr/tag_with_payload.md @@ -115,5 +115,5 @@ match shape { ~~~ # TYPES ~~~clojure -(expr @1.1-5.2 (type "Num(_size)")) +(expr @1.1-5.2 (type "Frac(_size)")) ~~~ diff --git a/test/snapshots/match_expr/variable_shadowing.md b/test/snapshots/match_expr/variable_shadowing.md index 0987b85bfb..7f73bd5db4 100644 --- a/test/snapshots/match_expr/variable_shadowing.md +++ b/test/snapshots/match_expr/variable_shadowing.md @@ -111,5 +111,5 @@ match (value, other) { ~~~ # TYPES ~~~clojure -(expr @1.1-4.2 (type "Num(_size)")) +(expr @1.1-4.2 (type "Error")) ~~~ diff --git a/test/snapshots/plume_package/Color.md b/test/snapshots/plume_package/Color.md index bab5a5227e..690f60f05f 100644 --- a/test/snapshots/plume_package/Color.md +++ b/test/snapshots/plume_package/Color.md @@ -115,7 +115,7 @@ I'm having trouble with this nominal tag: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The tag is: - _RGBA(U8, U8, U8, Num(_size))_ + _RGBA(U8, U8, U8, Frac(_size))_ But it should be one of: _[Hex(Str), Named(Str), RGB(U8, U8, U8), RGBA(U8, U8, U8, Dec)]_ diff --git a/test/snapshots/records/record_with_complex_types.md b/test/snapshots/records/record_with_complex_types.md index 950bbf5531..79ec501d83 100644 --- a/test/snapshots/records/record_with_complex_types.md +++ b/test/snapshots/records/record_with_complex_types.md @@ -234,5 +234,5 @@ CloseCurly(15:1-15:2),EndOfFile(15:2-15:2), ~~~ # TYPES ~~~clojure -(expr @1.1-15.2 (type "{ name: Str, scores: List(Num(_size)), status: [Active({ since: Str })]_others, preferences: { theme: [Dark]_others2, notifications: [Email(Str)]_others3 }, metadata: Result({ tags: List(Str), permissions: List([Read]_others4) }, err), callback: _arg -> Num(_size2), nested: { items: List([Some(Str)][None]_others5), result: [Success({ data: List(Num(_size3)), timestamp: Str })]_others6 } }")) +(expr @1.1-15.2 (type "{ name: Str, scores: List(Num(_size)), status: [Active({ since: Str })]_others, preferences: { theme: [Dark]_others2, notifications: [Email(Str)]_others3 }, metadata: Result({ tags: List(Str), permissions: List([Read]_others4) }, err), callback: Num(_size2) -> Num(_size3), nested: { items: List([Some(Str)][None]_others5), result: [Success({ data: List(Num(_size4)), timestamp: Str })]_others6 } }")) ~~~ diff --git a/test/snapshots/simple_lambda_constraint_success.md b/test/snapshots/simple_lambda_constraint_success.md index f2a706136c..edd14b134d 100644 --- a/test/snapshots/simple_lambda_constraint_success.md +++ b/test/snapshots/simple_lambda_constraint_success.md @@ -16,21 +16,36 @@ addTwoF64 : F64 -> F64 addTwoF64 = |x| x + 2.0 ~~~ # EXPECTED -TYPE MISMATCH - simple_lambda_constraint_success.md:8:20:8:23 +TYPE MISMATCH - simple_lambda_constraint_success.md:5:18:5:19 +TYPE MISMATCH - simple_lambda_constraint_success.md:9:21:9:24 # PROBLEMS **TYPE MISMATCH** This expression is used in an unexpected way: -**simple_lambda_constraint_success.md:8:20:8:23:** +**simple_lambda_constraint_success.md:5:18:5:19:** ```roc -addTwoF64 : F64 -> F64 +addTwo = |x| x + 2 ``` - ^^^ + ^ It is of type: - _F64_ + _Num(_size)_ But you are trying to use it as: - _Num(_size)_ + _I64_ + +**TYPE MISMATCH** +This expression is used in an unexpected way: +**simple_lambda_constraint_success.md:9:21:9:24:** +```roc +addTwoF64 = |x| x + 2.0 +``` + ^^^ + +It is of type: + _Frac(_size)_ + +But you are trying to use it as: + _F64_ # TOKENS ~~~zig @@ -115,9 +130,9 @@ NO CHANGE ~~~clojure (inferred-types (defs - (patt @5.1-5.7 (type "I64 -> I64")) + (patt @5.1-5.7 (type "Error -> Error")) (patt @9.1-9.10 (type "Error -> Error"))) (expressions - (expr @5.10-5.19 (type "I64 -> I64")) + (expr @5.10-5.19 (type "Error -> Error")) (expr @9.13-9.24 (type "Error -> Error")))) ~~~ diff --git a/test/snapshots/test_exact_pattern_crash.md b/test/snapshots/test_exact_pattern_crash.md index b149c129f6..9b7512940c 100644 --- a/test/snapshots/test_exact_pattern_crash.md +++ b/test/snapshots/test_exact_pattern_crash.md @@ -57,7 +57,7 @@ This expression is used in an unexpected way: ^^^^^^^^ It is of type: - _Num(_size), Num(_size2), _arg -> Num(_size3), _arg2 -> Num(_size4) -> _ret_ + _Num(_size), Num(_size2), Num(_size3) -> Num(_size4), Num(_size5) -> Num(_size6) -> _ret_ But you are trying to use it as: _Pair(a, b), a -> c, b -> d -> Pair(c, d)_ diff --git a/test/snapshots/type_anno_connection.md b/test/snapshots/type_anno_connection.md index f6f3a79fa3..8df3dd6417 100644 --- a/test/snapshots/type_anno_connection.md +++ b/test/snapshots/type_anno_connection.md @@ -14,20 +14,20 @@ my_number : U64 my_number = add_one(42) ~~~ # EXPECTED -TYPE MISMATCH - type_anno_connection.md:7:21:7:23 +TYPE MISMATCH - type_anno_connection.md:4:19:4:20 # PROBLEMS **TYPE MISMATCH** -The first argument to this function is not what I expect: -**type_anno_connection.md:7:21:7:23:** +This expression is used in an unexpected way: +**type_anno_connection.md:4:19:4:20:** ```roc -my_number = add_one(42) +add_one = |x| x + 1 ``` - ^^ + ^ -This argument is of type: +It is of type: _Num(_size)_ -But the function needs the first argumument to be: +But you are trying to use it as: _U64_ # TOKENS diff --git a/test/snapshots/type_annotation_basic.md b/test/snapshots/type_annotation_basic.md index c7f3ee21c6..c2ab320836 100644 --- a/test/snapshots/type_annotation_basic.md +++ b/test/snapshots/type_annotation_basic.md @@ -35,7 +35,7 @@ main! = |_| { ~~~ # EXPECTED UNUSED VARIABLE - type_annotation_basic.md:21:5:21:9 -TYPE MISMATCH - type_annotation_basic.md:24:21:24:22 +TYPE MISMATCH - type_annotation_basic.md:13:18:13:19 # PROBLEMS **UNUSED VARIABLE** Variable `pair` is not used anywhere in your code. @@ -50,17 +50,17 @@ The unused variable is declared here: **TYPE MISMATCH** -The first argument to this function is not what I expect: -**type_annotation_basic.md:24:21:24:22:** +This expression is used in an unexpected way: +**type_annotation_basic.md:13:18:13:19:** ```roc - result = addOne(5) +addOne = |n| n + 1 ``` - ^ + ^ -This argument is of type: +It is of type: _Num(_size)_ -But the function needs the first argumument to be: +But you are trying to use it as: _U64_ # TOKENS @@ -291,11 +291,11 @@ main! = |_| { (defs (patt @5.1-5.9 (type "a -> a")) (patt @9.1-9.8 (type "a, b -> (a, b)")) - (patt @13.1-13.7 (type "U64 -> U64")) + (patt @13.1-13.7 (type "Error -> Error")) (patt @15.1-15.6 (type "_arg -> Error"))) (expressions (expr @5.12-5.17 (type "a -> a")) (expr @9.11-9.42 (type "a, b -> (a, b)")) - (expr @13.10-13.19 (type "U64 -> U64")) + (expr @13.10-13.19 (type "Error -> Error")) (expr @15.9-27.2 (type "_arg -> Error")))) ~~~ diff --git a/test/snapshots/unused_vars_simple.md b/test/snapshots/unused_vars_simple.md index 53614c5379..45d02e3dec 100644 --- a/test/snapshots/unused_vars_simple.md +++ b/test/snapshots/unused_vars_simple.md @@ -256,12 +256,12 @@ main! = |_| { (patt @4.1-4.15 (type "_arg -> Num(_size)")) (patt @7.1-7.16 (type "_arg -> _ret")) (patt @10.1-10.18 (type "_arg -> Num(_size)")) - (patt @13.1-13.13 (type "_arg -> Num(_size)")) + (patt @13.1-13.13 (type "Num(_size) -> Num(_size2)")) (patt @15.1-15.6 (type "_arg -> Num(_size)"))) (expressions (expr @4.18-4.24 (type "_arg -> Num(_size)")) (expr @7.19-7.34 (type "_arg -> _ret")) (expr @10.21-10.35 (type "_arg -> Num(_size)")) - (expr @13.16-13.35 (type "_arg -> Num(_size)")) + (expr @13.16-13.35 (type "Num(_size) -> Num(_size2)")) (expr @15.9-21.2 (type "_arg -> Num(_size)")))) ~~~