diff --git a/src/check/Check.zig b/src/check/Check.zig index 723bc3d52d..dff7f48a55 100644 --- a/src/check/Check.zig +++ b/src/check/Check.zig @@ -1540,16 +1540,15 @@ fn checkBinopExpr(self: *Self, expr_idx: CIR.Expr.Idx, expr_region: Region, bino const rhs_var = @as(Var, @enumFromInt(@intFromEnum(binop.rhs))); const result_var = @as(Var, @enumFromInt(@intFromEnum(expr_idx))); - // Create a fresh number variable for the operation + // Create a SINGLE fresh number variable for the operation + // All operands and the result must be the same numeric type const num_content = Content{ .structure = .{ .num = .{ .num_unbound = .{ .sign_needed = false, .bits_needed = 0 } } } }; - const num_var_lhs = try self.freshFromContent(num_content, expr_region); - const num_var_rhs = try self.freshFromContent(num_content, expr_region); - const num_var_result = try self.freshFromContent(num_content, expr_region); + const num_var = try self.freshFromContent(num_content, expr_region); - // Unify lhs, rhs, and result with the number type - _ = try self.unify(num_var_lhs, lhs_var); - _ = try self.unify(num_var_rhs, rhs_var); - _ = try self.unify(result_var, num_var_result); + // Unify lhs, rhs, and result with the SAME number type + _ = try self.unify(num_var, lhs_var); + _ = try self.unify(num_var, rhs_var); + _ = try self.unify(num_var, result_var); return does_fx; }, diff --git a/src/check/problem.zig b/src/check/problem.zig index 2d8b96574b..0ba3a47204 100644 --- a/src/check/problem.zig +++ b/src/check/problem.zig @@ -320,7 +320,11 @@ pub const ReportBuilder = struct { try snapshot_writer.write(types.expected_snapshot); const owned_expected = try report.addOwnedString(self.buf.items[0..]); - const region = self.can_ir.store.regions.get(@enumFromInt(@intFromEnum(types.actual_var))); + // For annotation mismatches, we want to highlight the expression that doesn't match, + // not the annotation itself. When from_annotation is true and we're showing + // "The type annotation says...", the expression is in expected_var. + const region_var = if (types.from_annotation) types.expected_var else types.actual_var; + const region = self.can_ir.store.regions.get(@enumFromInt(@intFromEnum(region_var))); // Add source region highlighting const region_info = self.module_env.calcRegionInfo(region.*); @@ -1252,12 +1256,14 @@ pub const ReportBuilder = struct { try appendOrdinal(&self.buf, data.second_arg_index + 1); const second_arg_index = try report.addOwnedString(self.buf.items); + // The types from unification already have the correct snapshots + // expected = first argument, actual = second argument self.buf.clearRetainingCapacity(); - try snapshot_writer.write(types.actual_snapshot); + try snapshot_writer.write(types.expected_snapshot); const first_type = try report.addOwnedString(self.buf.items); self.buf.clearRetainingCapacity(); - try snapshot_writer.write(types.expected_snapshot); + try snapshot_writer.write(types.actual_snapshot); const second_type = try report.addOwnedString(self.buf.items); try report.document.addText("The "); 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/annotations.md b/test/snapshots/annotations.md index 8390631919..3ec4a2ea3f 100644 --- a/test/snapshots/annotations.md +++ b/test/snapshots/annotations.md @@ -49,10 +49,10 @@ fail_pair_diff_types = mk_pair("1", 2) ^^^ ^ The first argument is of type: - _Num(_size)_ + _Str_ But the second argument is of type: - _Str_ + _Num(_size)_ `mk_pair` needs these arguments to have compatible types. @@ -93,10 +93,10 @@ fail_with_implicit = mk_pair_inferred("str", 2) ^^^^^ ^ The first argument is of type: - _Num(_size)_ + _Str_ But the second argument is of type: - _Str_ + _Num(_size)_ `mk_pair_inferred` needs these arguments to have compatible types. diff --git a/test/snapshots/bound_type_var_no_annotation.md b/test/snapshots/bound_type_var_no_annotation.md index 71b75f18eb..88e996b41c 100644 --- a/test/snapshots/bound_type_var_no_annotation.md +++ b/test/snapshots/bound_type_var_no_annotation.md @@ -33,6 +33,7 @@ main! = |_| { ~~~ # EXPECTED UNUSED VARIABLE - bound_type_var_no_annotation.md:19:5:19:9 +TYPE MISMATCH - bound_type_var_no_annotation.md:11:18:11:19 # PROBLEMS **UNUSED VARIABLE** Variable `pair` is not used anywhere in your code. @@ -46,6 +47,20 @@ The unused variable is declared here: ^^^^ +**TYPE MISMATCH** +This expression is used in an unexpected way: +**bound_type_var_no_annotation.md:11:18:11:19:** +```roc +addOne = |n| n + 1 +``` + ^ + +It is of type: + _Num(_size)_ + +But you are trying to use it as: + _U64_ + # TOKENS ~~~zig KwApp(1:1-1:4),OpenSquare(1:5-1:6),LowerIdent(1:6-1:11),CloseSquare(1:11-1:12),OpenCurly(1:13-1:14),LowerIdent(1:15-1:17),OpColon(1:17-1:18),KwPlatform(1:19-1:27),StringStart(1:28-1:29),StringPart(1:29-1:50),StringEnd(1:50-1:51),CloseCurly(1:52-1:53), @@ -262,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 @13.1-13.6 (type "_arg -> 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 @13.9-25.2 (type "_arg -> U64")))) + (expr @11.10-11.19 (type "Error -> Error")) + (expr @13.9-25.2 (type "_arg -> Error")))) ~~~ diff --git a/test/snapshots/crash_and_ellipsis_test.md b/test/snapshots/crash_and_ellipsis_test.md index be9da8777b..4a94615816 100644 --- a/test/snapshots/crash_and_ellipsis_test.md +++ b/test/snapshots/crash_and_ellipsis_test.md @@ -34,7 +34,7 @@ main! = |_| { UNUSED VARIABLE - crash_and_ellipsis_test.md:20:5:20:12 UNUSED VARIABLE - crash_and_ellipsis_test.md:21:5:21:12 UNUSED VARIABLE - crash_and_ellipsis_test.md:22:5:22:12 -TYPE MISMATCH - crash_and_ellipsis_test.md:8:20:8:23 +TYPE MISMATCH - crash_and_ellipsis_test.md:9:17:11:2 # PROBLEMS **UNUSED VARIABLE** Variable `result1` is not used anywhere in your code. @@ -74,11 +74,12 @@ The unused variable is declared here: **TYPE MISMATCH** This expression is used in an unexpected way: -**crash_and_ellipsis_test.md:8:20:8:23:** +**crash_and_ellipsis_test.md:9:17:11:2:** ```roc -testCrash : U64 -> U64 +testCrash = |_| { + crash "This is a crash message" +} ``` - ^^^ The type annotation says it should have the type: _U64_ diff --git a/test/snapshots/fuzz_crash/fuzz_crash_025.md b/test/snapshots/fuzz_crash/fuzz_crash_025.md index 3f5a66099b..048ca833aa 100644 --- a/test/snapshots/fuzz_crash/fuzz_crash_025.md +++ b/test/snapshots/fuzz_crash/fuzz_crash_025.md @@ -41,7 +41,7 @@ PARSE ERROR - fuzz_crash_025.md:14:48:14:49 PARSE ERROR - fuzz_crash_025.md:15:1:15:2 PARSE ERROR - fuzz_crash_025.md:15:3:15:4 PARSE ERROR - fuzz_crash_025.md:15:4:15:5 -TYPE MISMATCH - fuzz_crash_025.md:13:5:13:9 +TYPE MISMATCH - fuzz_crash_025.md:14:5:14:48 # PROBLEMS **PARSE ERROR** Type applications require parentheses around their type arguments. @@ -153,11 +153,11 @@ f =8 **TYPE MISMATCH** This expression is used in an unexpected way: -**fuzz_crash_025.md:13:5:13:9:** +**fuzz_crash_025.md:14:5:14:48:** ```roc -e : U128 +e = 3402823669209384634633746074317682114553.14: I8 ``` - ^^^^ + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The type annotation says it should have the type: _U128_ diff --git a/test/snapshots/fuzz_crash/fuzz_crash_027.md b/test/snapshots/fuzz_crash/fuzz_crash_027.md index 4731de5f3c..5fced2c90b 100644 --- a/test/snapshots/fuzz_crash/fuzz_crash_027.md +++ b/test/snapshots/fuzz_crash/fuzz_crash_027.md @@ -227,7 +227,7 @@ UNDECLARED TYPE - fuzz_crash_027.md:153:9:153:14 INVALID IF CONDITION - fuzz_crash_027.md:50:5:50:5 INCOMPATIBLE MATCH PATTERNS - fuzz_crash_027.md:64:2:64:2 TYPE MISMATCH - fuzz_crash_027.md:111:2:113:3 -TYPE MISMATCH - fuzz_crash_027.md:99:9:99:38 +TYPE MISMATCH - fuzz_crash_027.md:100:9:148:2 # PROBLEMS **LEADING ZERO** Numbers cannot have leading zeros. @@ -920,11 +920,58 @@ But you are trying to use it as: **TYPE MISMATCH** This expression is used in an unexpected way: -**fuzz_crash_027.md:99:9:99:38:** +**fuzz_crash_027.md:100:9:148:2:** ```roc -main! : List(String) -> Result({}, _) +main! = |_| { # Yeah Ie + world = "World" + var number = 123 + expect blah == 1 + tag = Blue + return # Comd + tag + + # Jusnt! + + ... + match_time( + ..., # + ) + some_func( + dbg # bug + 42, # Aft expr + ) + crash "Unreachtement + tag_with = Ok(number) + ited = "Hello, ${world}" + list = [ + add_one( + dbg # Afin list +e[, # afarg + ), 456, # ee + ] + for n in list { + line!("Adding ${n} to ${number}") + number = number + n + } + record = { foo: 123, bar: "Hello", baz: tag, qux: Ok(world), punned } + tuple = (123, "World", tag, Ok(world), (nested, tuple), [1, 2, 3]) + m_tuple = ( + 123, + "World", + tag1, + Ok(world), # Thisnt + (nested, tuple), + [1, 2, 3], + ) + bsult = Err(foo) ?? 12 > 5 * 5 or 13 + 2 < 5 and 10 - 1 >= 16 or 12 <= 3 / 5 + stale = some_fn(arg1)?.statod()?.ned()?.recd? + Stdoline!( + "How about ${ # + Num.toStr(number) # on expr + } as a", + ) +} # Commenl decl ``` - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The type annotation says it should have the type: _List(Error) -> Result({ }, _d)_ diff --git a/test/snapshots/issue/underscore_error_propagation.md b/test/snapshots/issue/underscore_error_propagation.md index d42ac357f9..d769755f7e 100644 --- a/test/snapshots/issue/underscore_error_propagation.md +++ b/test/snapshots/issue/underscore_error_propagation.md @@ -23,7 +23,7 @@ goodValue = "test" ~~~ # EXPECTED UNDERSCORE IN TYPE ALIAS - underscore_error_propagation.md:1:1:1:1 -TYPE MISMATCH - underscore_error_propagation.md:14:13:14:24 +TYPE MISMATCH - underscore_error_propagation.md:15:13:15:19 # PROBLEMS **UNDERSCORE IN TYPE ALIAS** Underscores are not allowed in type alias declarations. @@ -38,11 +38,11 @@ Underscores in type annotations mean "I don't care about this type", which doesn **TYPE MISMATCH** This expression is used in an unexpected way: -**underscore_error_propagation.md:14:13:14:24:** +**underscore_error_propagation.md:15:13:15:19:** ```roc -goodValue : GoodDerived +goodValue = "test" ``` - ^^^^^^^^^^^ + ^^^^^^ The type annotation says it should have the type: _GoodDerived_ diff --git a/test/snapshots/lambda_annotation_mismatch_error.md b/test/snapshots/lambda_annotation_mismatch_error.md index 65de349cbb..91f0021428 100644 --- a/test/snapshots/lambda_annotation_mismatch_error.md +++ b/test/snapshots/lambda_annotation_mismatch_error.md @@ -17,6 +17,7 @@ wrong_type_function = |x| x * 3.14 ~~~ # EXPECTED TYPE MISMATCH - lambda_annotation_mismatch_error.md:5:23:5:24 +TYPE MISMATCH - lambda_annotation_mismatch_error.md:9:31:9:35 # PROBLEMS **TYPE MISMATCH** This expression is used in an unexpected way: @@ -32,6 +33,20 @@ It is of type: But you are trying to use it as: _Num(_size)_ +**TYPE MISMATCH** +This expression is used in an unexpected way: +**lambda_annotation_mismatch_error.md:9:31:9:35:** +```roc +wrong_type_function = |x| x * 3.14 +``` + ^^^^ + +It is of type: + _Frac(_size)_ + +But you are trying to use it as: + _I64_ + # TOKENS ~~~zig KwModule(1:1-1:7),OpenSquare(1:8-1:9),LowerIdent(1:9-1:24),Comma(1:24-1:25),LowerIdent(1:26-1:45),CloseSquare(1:45-1:46), @@ -116,8 +131,8 @@ NO CHANGE (inferred-types (defs (patt @5.1-5.16 (type "Error -> Error")) - (patt @9.1-9.20 (type "I64 -> I64"))) + (patt @9.1-9.20 (type "Error -> Error"))) (expressions (expr @5.19-5.29 (type "Error -> Error")) - (expr @9.23-9.35 (type "I64 -> I64")))) + (expr @9.23-9.35 (type "Error -> Error")))) ~~~ diff --git a/test/snapshots/lambda_capture/lambda_invalid_references.md b/test/snapshots/lambda_capture/lambda_invalid_references.md index 533a9d7e86..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 "Num(_size) -> _arg -> Num(_size2)")) +(expr @1.1-1.14 (type "Error -> _arg -> Error")) ~~~ diff --git a/test/snapshots/lambda_multi_arg_mismatch.md b/test/snapshots/lambda_multi_arg_mismatch.md index a205ad8457..52af6c8a9f 100644 --- a/test/snapshots/lambda_multi_arg_mismatch.md +++ b/test/snapshots/lambda_multi_arg_mismatch.md @@ -79,10 +79,10 @@ The first and third arguments to `multi_arg_fn` must have compatible types, but ^^^^^^^ The first argument is of type: - _Str_ + _Num(_size)_ But the third argument is of type: - _Num(_size)_ + _Str_ `multi_arg_fn` needs these arguments to have compatible types. diff --git a/test/snapshots/lambda_parameter_unused.md b/test/snapshots/lambda_parameter_unused.md index ab567640b4..f6fb8dd94f 100644 --- a/test/snapshots/lambda_parameter_unused.md +++ b/test/snapshots/lambda_parameter_unused.md @@ -34,6 +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:9:32:9:33 # PROBLEMS **UNUSED VARIABLE** Variable `unused` is not used anywhere in your code. @@ -59,6 +60,20 @@ multiply = |_factor| _factor * 2 ^^^^^^^ +**TYPE MISMATCH** +This expression is used in an unexpected way: +**lambda_parameter_unused.md:9:32:9:33:** +```roc +multiply = |_factor| _factor * 2 +``` + ^ + +It is of type: + _Num(_size)_ + +But you are trying to use it as: + _U64_ + # TOKENS ~~~zig KwApp(1:1-1:4),OpenSquare(1:5-1:6),LowerIdent(1:6-1:11),CloseSquare(1:11-1:12),OpenCurly(1:13-1:14),LowerIdent(1:15-1:17),OpColon(1:17-1:18),KwPlatform(1:19-1:27),StringStart(1:28-1:29),StringPart(1:29-1:50),StringEnd(1:50-1:51),CloseCurly(1:52-1:53), @@ -305,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 991abab23e..953dd30537 100644 --- a/test/snapshots/lambda_ret_constraint_bug.md +++ b/test/snapshots/lambda_ret_constraint_bug.md @@ -14,9 +14,22 @@ main : I64, I64 -> I64 main = |_, _| helper(5) ~~~ # EXPECTED -NIL +TYPE MISMATCH - lambda_ret_constraint_bug.md:4:18:4:19 # PROBLEMS -NIL +**TYPE MISMATCH** +This expression is used in an unexpected way: +**lambda_ret_constraint_bug.md:4:18:4:19:** +```roc +helper = |n| n * 2 +``` + ^ + +It is of type: + _Num(_size)_ + +But you are trying to use it as: + _I64_ + # TOKENS ~~~zig KwApp(1:1-1:4),OpenSquare(1:5-1:6),LowerIdent(1:6-1:10),CloseSquare(1:10-1:11),OpenCurly(1:12-1:13),LowerIdent(1:14-1:16),OpColon(1:16-1:17),KwPlatform(1:18-1:26),StringStart(1:27-1:28),StringPart(1:28-1:45),StringEnd(1:45-1:46),CloseCurly(1:47-1:48), @@ -112,9 +125,9 @@ NO CHANGE ~~~clojure (inferred-types (defs - (patt @4.1-4.7 (type "I64 -> I64")) - (patt @7.1-7.5 (type "I64, I64 -> I64"))) + (patt @4.1-4.7 (type "Error -> Error")) + (patt @7.1-7.5 (type "Error, Error -> Error"))) (expressions - (expr @4.10-4.19 (type "I64 -> I64")) - (expr @7.8-7.24 (type "I64, I64 -> I64")))) + (expr @4.10-4.19 (type "Error -> Error")) + (expr @7.8-7.24 (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_numbers.md b/test/snapshots/let_polymorphism_numbers.md index cf65292381..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 @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 @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/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 1a9bbc5b42..8dad6c9e4c 100644 --- a/test/snapshots/plume_package/Color.md +++ b/test/snapshots/plume_package/Color.md @@ -81,7 +81,7 @@ is_named_color = |str|{ UNUSED VARIABLE - Color.md:30:5:30:25 UNDEFINED VARIABLE - Color.md:68:14:68:27 INVALID NOMINAL TAG - Color.md:23:5:23:33 -TYPE MISMATCH - Color.md:26:7:26:46 +TYPE MISMATCH - Color.md:27:7:46:2 # PROBLEMS **UNUSED VARIABLE** Variable `is_char_in_hex_range` is not used anywhere in your code. @@ -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)]_ @@ -126,11 +126,29 @@ But it should be one of: **TYPE MISMATCH** This expression is used in an unexpected way: -**Color.md:26:7:26:46:** +**Color.md:27:7:46:2:** ```roc -hex : Str -> Result(Color, [InvalidHex(Str)]) +hex = |str| { + + bytes = str.to_utf8() + is_char_in_hex_range = |b| (b >= '0' and b <= '9') or (b >= 'a' and b <= 'f') or (b >= 'A' and b <= 'F') + + match bytes { + ['#', a, b, c, d, e, f] => { + is_valid = + a.is_char_in_hex_range() + and b.is_char_in_hex_range() + and c.is_char_in_hex_range() + and d.is_char_in_hex_range() + and e.is_char_in_hex_range() + and f.is_char_in_hex_range() + + if is_valid Ok(Color.Hex(str)) else Err(InvalidHex("Expected Hex to be in the range 0-9, a-f, A-F, got ${str}")) + } + _ => Err(InvalidHex("Expected Hex must start with # and be 7 characters long, got ${str}")) + } +} ``` - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The type annotation says it should have the type: _Str -> Result(Error, [InvalidHex(Str)])_ diff --git a/test/snapshots/simple_lambda_constraint_success.md b/test/snapshots/simple_lambda_constraint_success.md index b9a174655e..afbf7dcd5f 100644 --- a/test/snapshots/simple_lambda_constraint_success.md +++ b/test/snapshots/simple_lambda_constraint_success.md @@ -16,8 +16,23 @@ addTwoF64 : F64 -> F64 addTwoF64 = |x| x + 2.0 ~~~ # EXPECTED +TYPE MISMATCH - simple_lambda_constraint_success.md:5:18:5:19 TYPE MISMATCH - simple_lambda_constraint_success.md:9:17:9:18 # PROBLEMS +**TYPE MISMATCH** +This expression is used in an unexpected way: +**simple_lambda_constraint_success.md:5:18:5:19:** +```roc +addTwo = |x| x + 2 +``` + ^ + +It is of type: + _Num(_size)_ + +But you are trying to use it as: + _I64_ + **TYPE MISMATCH** This expression is used in an unexpected way: **simple_lambda_constraint_success.md:9:17:9:18:** @@ -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/type_anno_connection.md b/test/snapshots/type_anno_connection.md index 2731d78adf..8df3dd6417 100644 --- a/test/snapshots/type_anno_connection.md +++ b/test/snapshots/type_anno_connection.md @@ -14,9 +14,22 @@ my_number : U64 my_number = add_one(42) ~~~ # EXPECTED -NIL +TYPE MISMATCH - type_anno_connection.md:4:19:4:20 # PROBLEMS -NIL +**TYPE MISMATCH** +This expression is used in an unexpected way: +**type_anno_connection.md:4:19:4:20:** +```roc +add_one = |x| x + 1 +``` + ^ + +It is of type: + _Num(_size)_ + +But you are trying to use it as: + _U64_ + # TOKENS ~~~zig KwModule(1:1-1:7),OpenSquare(1:8-1:9),LowerIdent(1:9-1:16),Comma(1:16-1:17),LowerIdent(1:18-1:27),CloseSquare(1:27-1:28), @@ -90,9 +103,9 @@ NO CHANGE ~~~clojure (inferred-types (defs - (patt @4.1-4.8 (type "U64 -> U64")) - (patt @7.1-7.10 (type "U64"))) + (patt @4.1-4.8 (type "Error -> Error")) + (patt @7.1-7.10 (type "Error"))) (expressions - (expr @4.11-4.20 (type "U64 -> U64")) - (expr @7.13-7.24 (type "U64")))) + (expr @4.11-4.20 (type "Error -> Error")) + (expr @7.13-7.24 (type "Error")))) ~~~ diff --git a/test/snapshots/type_annotation_basic.md b/test/snapshots/type_annotation_basic.md index 1393606281..c2ab320836 100644 --- a/test/snapshots/type_annotation_basic.md +++ b/test/snapshots/type_annotation_basic.md @@ -35,6 +35,7 @@ main! = |_| { ~~~ # EXPECTED UNUSED VARIABLE - type_annotation_basic.md:21:5:21:9 +TYPE MISMATCH - type_annotation_basic.md:13:18:13:19 # PROBLEMS **UNUSED VARIABLE** Variable `pair` is not used anywhere in your code. @@ -48,6 +49,20 @@ The unused variable is declared here: ^^^^ +**TYPE MISMATCH** +This expression is used in an unexpected way: +**type_annotation_basic.md:13:18:13:19:** +```roc +addOne = |n| n + 1 +``` + ^ + +It is of type: + _Num(_size)_ + +But you are trying to use it as: + _U64_ + # TOKENS ~~~zig KwApp(1:1-1:4),OpenSquare(1:5-1:6),LowerIdent(1:6-1:11),CloseSquare(1:11-1:12),OpenCurly(1:13-1:14),LowerIdent(1:15-1:17),OpColon(1:17-1:18),KwPlatform(1:19-1:27),StringStart(1:28-1:29),StringPart(1:29-1:50),StringEnd(1:50-1:51),CloseCurly(1:52-1:53), @@ -276,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 @15.1-15.6 (type "_arg -> 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 @15.9-27.2 (type "_arg -> U64")))) + (expr @13.10-13.19 (type "Error -> Error")) + (expr @15.9-27.2 (type "_arg -> Error")))) ~~~ diff --git a/test/snapshots/type_app_complex_nested.md b/test/snapshots/type_app_complex_nested.md index 7675302b11..b3014335dc 100644 --- a/test/snapshots/type_app_complex_nested.md +++ b/test/snapshots/type_app_complex_nested.md @@ -33,7 +33,7 @@ UNDECLARED TYPE - type_app_complex_nested.md:4:30:4:35 UNDECLARED TYPE - type_app_complex_nested.md:4:51:4:56 UNUSED VARIABLE - type_app_complex_nested.md:7:12:7:21 UNDECLARED TYPE - type_app_complex_nested.md:12:14:12:19 -TYPE MISMATCH - type_app_complex_nested.md:12:55:12:56 +TYPE MISMATCH - type_app_complex_nested.md:13:18:15:2 # PROBLEMS **UNDECLARED TYPE** The type _Maybe_ is not declared in this scope. @@ -104,11 +104,12 @@ deepNested : Maybe(Result(List(Dict(Str, a)), _b)) -> a **TYPE MISMATCH** This expression is used in an unexpected way: -**type_app_complex_nested.md:12:55:12:56:** +**type_app_complex_nested.md:13:18:15:2:** ```roc -deepNested : Maybe(Result(List(Dict(Str, a)), _b)) -> a +deepNested = |_| { + crash "not implemented" +} ``` - ^ The type annotation says it should have the type: _a_ diff --git a/test/snapshots/type_var_underscore_conventions.md b/test/snapshots/type_var_underscore_conventions.md index 793cfd27ed..efeadd7768 100644 --- a/test/snapshots/type_var_underscore_conventions.md +++ b/test/snapshots/type_var_underscore_conventions.md @@ -34,7 +34,7 @@ UNUSED VARIABLE - type_var_underscore_conventions.md:9:22:9:26 UNUSED VARIABLE - type_var_underscore_conventions.md:13:17:13:18 UNUSED VARIABLE - type_var_underscore_conventions.md:17:17:17:18 UNUSED VARIABLE - type_var_underscore_conventions.md:22:9:22:10 -TYPE MISMATCH - type_var_underscore_conventions.md:8:36:8:41 +TYPE MISMATCH - type_var_underscore_conventions.md:9:28:9:37 # PROBLEMS **UNUSED VARIABLE** Variable `x` is not used anywhere in your code. @@ -98,11 +98,11 @@ main = |x| "done" **TYPE MISMATCH** This expression is used in an unexpected way: -**type_var_underscore_conventions.md:8:36:8:41:** +**type_var_underscore_conventions.md:9:28:9:37:** ```roc -ending_underscore : List(elem_) -> elem_ +ending_underscore = |list| "default" ``` - ^^^^^ + ^^^^^^^^^ The type annotation says it should have the type: _elem__