From fa19fabd882d2abf5cc7ae89cc0d74e98a73ccc3 Mon Sep 17 00:00:00 2001 From: Jared Ramirez Date: Mon, 22 Dec 2025 10:26:10 -0500 Subject: [PATCH] Regenerate snapshots & move fns around in writer --- src/canonicalize/ModuleEnv.zig | 29 +- src/check/problem.zig | 175 +- src/check/snapshot.zig | 2 +- src/check/test/TestEnv.zig | 6 +- src/check/test/cross_module_test.zig.bak | 222 -- .../let_polymorphism_integration_test.zig.bak | 254 -- src/check/test/num_type_inference_test.zig | 8 +- .../test/type_checking_integration.zig.bak | 2754 ----------------- src/check/test/unify_test.zig | 8 +- src/check/test/where_clause_test.zig.bak | 320 -- src/compile/test/type_printing_bug_test.zig | 2 +- src/types/TypeWriter.zig | 234 +- test/snapshots/annotations.md | 22 +- test/snapshots/arrow_qualified_functions.md | 12 +- .../binop_omnibus__single__no_spaces.md | 2 +- test/snapshots/binops.md | 10 +- test/snapshots/can_closure_captures.md | 22 +- test/snapshots/can_list_first_concrete.md | 4 +- test/snapshots/can_list_heterogeneous.md | 4 +- .../can_list_mismatch_then_nested_error.md | 10 +- test/snapshots/can_list_multiline_mismatch.md | 4 +- .../can_list_nested_heterogeneous.md | 2 +- .../can_list_triple_nested_heterogeneous.md | 2 +- test/snapshots/can_list_two_elements.md | 2 +- .../can_nested_heterogeneous_lists.md | 4 +- test/snapshots/comprehensive/Container.md | 18 +- test/snapshots/eval/call_float_literal.md | 3 +- test/snapshots/eval/tuple_numbers.md | 18 +- test/snapshots/expr/ann_effectful_fn.md | 6 +- test/snapshots/expr/list_type_err.md | 2 +- test/snapshots/expr/not_tag.md | 8 +- .../expr/record_literal_field_bang.md | 3 +- test/snapshots/expr/record_simple.md | 3 +- test/snapshots/expr/record_updater_basic.md | 12 +- test/snapshots/expr/record_updater_chained.md | 24 +- .../snapshots/expr/tag_applications_simple.md | 13 +- test/snapshots/expr/tag_vs_function_calls.md | 8 +- test/snapshots/expr/tag_with_payload.md | 3 +- test/snapshots/expr/tuple.md | 3 +- test/snapshots/expr/tuple_simple_unbound.md | 3 +- test/snapshots/expr/tuple_type.md | 4 +- test/snapshots/expr/two_arg_closure.md | 3 +- test/snapshots/expr_if_missing_else.md | 3 +- .../formatting/multiline/everything.md | 2 - .../formatting/singleline/everything.md | 2 - .../singleline_with_comma/everything.md | 2 - test/snapshots/fuzz_crash/fuzz_crash_019.md | 43 +- test/snapshots/fuzz_crash/fuzz_crash_020.md | 40 +- test/snapshots/fuzz_crash/fuzz_crash_023.md | 35 +- test/snapshots/fuzz_crash/fuzz_crash_027.md | 36 +- test/snapshots/fuzz_crash/fuzz_crash_028.md | Bin 59525 -> 59515 bytes test/snapshots/fuzz_crash/fuzz_crash_047.md | 12 +- test/snapshots/fuzz_crash/fuzz_crash_049.md | Bin 122209 -> 122127 bytes test/snapshots/if_then_else/if_then_else_9.md | 8 +- .../if_then_else/if_then_else_nested_chain.md | 12 +- .../if_then_else_simple_block_formatting.md | 3 +- .../if_then_else/if_then_else_simple_file.md | 8 +- .../if_then_else/if_then_else_simple_tag.md | 6 +- .../issue/simple_underscore_error.md | 2 +- .../snapshots/issue/test_error_propagation.md | 6 +- .../issue/underscore_error_propagation.md | 12 +- test/snapshots/issue/underscore_error_type.md | 28 +- test/snapshots/issue/usage_test.md | 2 +- .../lambda_annotation_mismatch_error.md | 4 +- test/snapshots/lambda_multi_arg_mismatch.md | 10 +- test/snapshots/let_polymorphism_complex.md | 104 +- test/snapshots/let_polymorphism_error.md | 2 +- test/snapshots/let_polymorphism_expr.md | 3 +- test/snapshots/let_polymorphism_records.md | 68 +- test/snapshots/match_expr/basic_tag_union.md | 2 +- test/snapshots/match_expr/literal_patterns.md | 9 +- .../match_expr/pattern_alternatives_mixed.md | 10 +- test/snapshots/match_expr/pattern_as_basic.md | 6 +- .../match_expr/record_pattern_edge_cases.md | 6 +- test/snapshots/multiline_string_complex.md | 8 +- .../nominal/nominal_associated_in_tuples.md | 1 - test/snapshots/nominal/nominal_tag_simple.md | 6 +- test/snapshots/numbers.md | 15 +- .../numeric_let_generalize_in_block.md | 6 +- test/snapshots/plume_package/Color.md | 20 +- .../records/error_duplicate_fields.md | 3 +- .../function_record_parameter_capture.md | 3 +- test/snapshots/records/polymorphism.md | 11 +- .../records/record_different_fields_error.md | 15 +- .../record_different_fields_reserved_error.md | 6 +- .../records/record_mixed_field_syntax.md | 3 +- test/snapshots/records/record_mixed_types.md | 7 +- test/snapshots/records/record_nested.md | 7 +- .../records/record_with_complex_types.md | 7 +- test/snapshots/static_dispatch/Adv.md | 6 +- .../plus_operator_vs_method.md | 4 +- .../string_interpolation_type_mismatch.md | 6 +- test/snapshots/syntax_grab_bag.md | 32 +- test/snapshots/test_exact_pattern_crash.md | 3 +- .../test_instantiated_arg_mismatch.md | 2 +- .../test_instantiated_return_crash.md | 6 +- .../test_instantiation_arity_mismatch.md | 3 +- .../test_nested_instantiation_crash.md | 6 +- .../test_tuple_instantiation_crash.md | 3 +- test/snapshots/type_alias_parameterized.md | 3 +- .../type_annotation_missing_parens.md | 1 - test/snapshots/type_app_complex_nested.md | 2 - test/snapshots/type_app_multiple_args.md | 1 - test/snapshots/type_app_with_vars.md | 3 +- test/snapshots/type_comprehensive_scope.md | 1 - test/snapshots/type_local_scope_vars.md | 6 +- test/snapshots/type_record_basic.md | 8 +- test/snapshots/type_var_mismatch.md | 2 +- .../type_var_underscore_conventions.md | 6 +- .../where_clause/where_clauses_10.md | 1 - .../snapshots/where_clause/where_clauses_4.md | 1 - .../where_clauses_serde_example.md | 6 +- 112 files changed, 618 insertions(+), 4346 deletions(-) delete mode 100644 src/check/test/cross_module_test.zig.bak delete mode 100644 src/check/test/let_polymorphism_integration_test.zig.bak delete mode 100644 src/check/test/type_checking_integration.zig.bak delete mode 100644 src/check/test/where_clause_test.zig.bak diff --git a/src/canonicalize/ModuleEnv.zig b/src/canonicalize/ModuleEnv.zig index 4bd5459c83..e52c74b190 100644 --- a/src/canonicalize/ModuleEnv.zig +++ b/src/canonicalize/ModuleEnv.zig @@ -2454,6 +2454,10 @@ pub fn pushTypesToSExprTree(self: *Self, maybe_expr_idx: ?CIR.Expr.Idx, tree: *S if (maybe_expr_idx) |expr_idx| { try self.pushExprTypesToSExprTree(expr_idx, tree); } else { + // Create a TypeWriter to format the type + var type_writer = try self.initTypeWriter(); + defer type_writer.deinit(); + // Generate full type information for all definitions and expressions const root_begin = tree.beginNode(); try tree.pushStaticAtom("inferred-types"); @@ -2483,12 +2487,8 @@ pub fn pushTypesToSExprTree(self: *Self, maybe_expr_idx: ?CIR.Expr.Idx, tree: *S const pattern_node_idx: CIR.Node.Idx = @enumFromInt(@intFromEnum(def.pattern)); const pattern_region = self.store.getRegionAt(pattern_node_idx); - // Create a TypeWriter to format the type - var type_writer = self.initTypeWriter() catch continue; - defer type_writer.deinit(); - // Write the type to the buffer - type_writer.write(pattern_var) catch continue; + try type_writer.write(pattern_var, .one_line); // Add the pattern type entry const patt_begin = tree.beginNode(); @@ -2537,12 +2537,8 @@ pub fn pushTypesToSExprTree(self: *Self, maybe_expr_idx: ?CIR.Expr.Idx, tree: *S // Get the type variable for this statement const stmt_var = varFrom(stmt_idx); - // Create a TypeWriter to format the type - var type_writer = self.initTypeWriter() catch continue; - defer type_writer.deinit(); - // Write the type to the buffer - type_writer.write(stmt_var) catch continue; + try type_writer.write(stmt_var, .one_line); const type_str = type_writer.get(); try tree.pushStringPair("type", type_str); @@ -2566,12 +2562,8 @@ pub fn pushTypesToSExprTree(self: *Self, maybe_expr_idx: ?CIR.Expr.Idx, tree: *S // Get the type variable for this statement const stmt_var = varFrom(stmt_idx); - // Create a TypeWriter to format the type - var type_writer = self.initTypeWriter() catch continue; - defer type_writer.deinit(); - // Write the type to the buffer - type_writer.write(stmt_var) catch continue; + try type_writer.write(stmt_var, .one_line); const type_str = type_writer.get(); try tree.pushStringPair("type", type_str); @@ -2606,11 +2598,8 @@ pub fn pushTypesToSExprTree(self: *Self, maybe_expr_idx: ?CIR.Expr.Idx, tree: *S const expr_region = self.store.getRegionAt(expr_node_idx); // Create a TypeWriter to format the type - var type_writer = self.initTypeWriter() catch continue; - defer type_writer.deinit(); - // Write the type to the buffer - type_writer.write(expr_var) catch continue; + try type_writer.write(expr_var, .one_line); // Add the expression type entry const expr_begin = tree.beginNode(); @@ -2643,7 +2632,7 @@ fn pushExprTypesToSExprTree(self: *Self, expr_idx: CIR.Expr.Idx, tree: *SExprTre defer type_writer.deinit(); // Write the type to the buffer - try type_writer.write(expr_var); + try type_writer.write(expr_var, .one_line); // Add the formatted type to the S-expression tree const type_str = type_writer.get(); diff --git a/src/check/problem.zig b/src/check/problem.zig index 937977eef8..d28e6f05a8 100644 --- a/src/check/problem.zig +++ b/src/check/problem.zig @@ -588,8 +588,8 @@ pub const ReportBuilder = struct { try report.document.addText("It has the type:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(owned_actual, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(owned_actual); try report.document.addLineBreak(); try report.document.addLineBreak(); @@ -599,8 +599,8 @@ pub const ReportBuilder = struct { try report.document.addText("But I expected it to be:"); } try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(owned_expected, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(owned_expected); return report; } @@ -707,8 +707,8 @@ pub const ReportBuilder = struct { try report.document.addText(expected_type_ordinal); try report.document.addText(" element has this type:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(expected_type, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(expected_type); try report.document.addLineBreak(); try report.document.addLineBreak(); @@ -717,8 +717,8 @@ pub const ReportBuilder = struct { try report.document.addText(actual_type_ordinal); try report.document.addText(" element has this type:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(actual_type, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(actual_type); try report.document.addLineBreak(); try report.document.addLineBreak(); @@ -791,8 +791,8 @@ pub const ReportBuilder = struct { // Add description try report.document.addText("Right now, it has the type:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(actual_type, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(actual_type); try report.document.addLineBreak(); // Add explanation @@ -914,8 +914,8 @@ pub const ReportBuilder = struct { try report.document.addText(" branch has this type:"); } try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(actual_type, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(actual_type); try report.document.addLineBreak(); try report.document.addLineBreak(); @@ -930,8 +930,8 @@ pub const ReportBuilder = struct { try report.document.addText("But all the previous branches have this type:"); } try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(expected_type, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(expected_type); try report.document.addLineBreak(); try report.document.addLineBreak(); @@ -1015,8 +1015,8 @@ pub const ReportBuilder = struct { // Show the type of the invalid branch try report.document.addText("The first pattern has the type:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(actual_type, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(actual_type); try report.document.addLineBreak(); try report.document.addLineBreak(); @@ -1025,14 +1025,12 @@ pub const ReportBuilder = struct { try report.document.addAnnotated("match", .keyword); try report.document.addText(" parenthesis has the type:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(expected_type, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(expected_type); try report.document.addLineBreak(); try report.document.addLineBreak(); try report.document.addText("These two types can never match!"); - try report.document.addLineBreak(); - try report.document.addLineBreak(); return report; } @@ -1124,8 +1122,8 @@ pub const ReportBuilder = struct { try report.document.addText(branch_ord); try report.document.addText(" pattern has this type:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(actual_type, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(actual_type); try report.document.addLineBreak(); try report.document.addLineBreak(); @@ -1136,8 +1134,8 @@ pub const ReportBuilder = struct { try report.document.addText("But the other pattern has this type:"); } try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(expected_type, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(expected_type); try report.document.addLineBreak(); try report.document.addLineBreak(); @@ -1145,8 +1143,6 @@ pub const ReportBuilder = struct { try report.document.addText("All patterns in an "); try report.document.addAnnotated("match", .keyword); try report.document.addText(" must have compatible types."); - try report.document.addLineBreak(); - try report.document.addLineBreak(); return report; } @@ -1235,8 +1231,8 @@ pub const ReportBuilder = struct { try report.document.addText(branch_ord); try report.document.addText(" branch has this type;"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(actual_type, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(actual_type); try report.document.addLineBreak(); try report.document.addLineBreak(); @@ -1249,8 +1245,8 @@ pub const ReportBuilder = struct { try report.document.addText("But the previous branch has this type:"); } try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(expected_type, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(expected_type); try report.document.addLineBreak(); try report.document.addLineBreak(); @@ -1345,8 +1341,8 @@ pub const ReportBuilder = struct { } try report.document.addText(" side is:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(actual_type, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(actual_type); try report.document.addLineBreak(); try report.document.addLineBreak(); @@ -1400,8 +1396,8 @@ pub const ReportBuilder = struct { // Show the invalid tag try report.document.addText("The tag is:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(actual_tag_str, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(actual_tag_str); try report.document.addLineBreak(); try report.document.addLineBreak(); @@ -1414,15 +1410,15 @@ pub const ReportBuilder = struct { try report.document.addText("But the nominal type needs it to be:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(expected_tag_str, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(expected_tag_str); } else { const expected_type = try report.addOwnedString(self.getFormattedString(types.expected_snapshot)); try report.document.addText("But the nominal type needs it to one of:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(expected_type, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(expected_type); // Check if there's a tag with the same name in the list of possible tags @@ -1440,9 +1436,7 @@ pub const ReportBuilder = struct { try report.document.addAnnotated("Hint:", .emphasized); try report.document.addReflowingText(" The nominal type has a tag with the same name, but different args:"); try report.document.addLineBreak(); - try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(cur_expected_tag_str, .type_variable); + try report.document.addCodeBlock(cur_expected_tag_str); break; } @@ -1479,15 +1473,15 @@ pub const ReportBuilder = struct { try report.document.addText("The record I found is:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(actual_type, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(actual_type); try report.document.addLineBreak(); try report.document.addLineBreak(); try report.document.addText("But the nominal type expects:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(expected_type, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(expected_type); return report; } @@ -1519,15 +1513,15 @@ pub const ReportBuilder = struct { try report.document.addText("The tuple I found is:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(actual_type, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(actual_type); try report.document.addLineBreak(); try report.document.addLineBreak(); try report.document.addText("But the nominal type expects:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(expected_type, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(expected_type); return report; } @@ -1559,15 +1553,15 @@ pub const ReportBuilder = struct { try report.document.addText("The value I found has type:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(actual_type, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(actual_type); try report.document.addLineBreak(); try report.document.addLineBreak(); try report.document.addText("But the nominal type expects:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(expected_type, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(expected_type); return report; } @@ -1610,8 +1604,8 @@ pub const ReportBuilder = struct { try report.document.addReflowingText("This argument has the type:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(actual_type, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(actual_type); try report.document.addLineBreak(); try report.document.addLineBreak(); @@ -1626,8 +1620,8 @@ pub const ReportBuilder = struct { try report.document.addReflowingText(arg_index); try report.document.addReflowingText(" argument to be:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(expected_type, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(expected_type); return report; } @@ -1723,8 +1717,8 @@ pub const ReportBuilder = struct { try report.document.addText(first_arg_index); try report.document.addReflowingText(" argument has the type:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(first_type, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(first_type); try report.document.addLineBreak(); try report.document.addLineBreak(); @@ -1732,8 +1726,8 @@ pub const ReportBuilder = struct { try report.document.addText(second_arg_index); try report.document.addReflowingText(" argument has the type:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(second_type, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(second_type); try report.document.addLineBreak(); try report.document.addLineBreak(); @@ -1803,7 +1797,6 @@ pub const ReportBuilder = struct { self.source, self.module_env.getLineStarts(), ); - try report.document.addLineBreak(); return report; } @@ -1865,8 +1858,8 @@ pub const ReportBuilder = struct { // Show the function signature try report.document.addReflowingText("The function has the signature:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(fn_type, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(fn_type); return report; } @@ -1904,7 +1897,6 @@ pub const ReportBuilder = struct { try report.document.addLineBreak(); try report.document.addReflowingText("Type aliases cannot be recursive. If you need a recursive type, use a nominal type (:=) instead of an alias (:)."); - try report.document.addLineBreak(); return report; } @@ -1938,7 +1930,6 @@ pub const ReportBuilder = struct { try report.document.addLineBreak(); try report.document.addReflowingText("This syntax was used for abilities, which have been removed from Roc. Use method constraints like `where [a.methodName(args) -> ret]` instead."); - try report.document.addLineBreak(); return report; } @@ -1982,9 +1973,7 @@ pub const ReportBuilder = struct { try report.document.addReflowingText(", is:"); try report.document.addLineBreak(); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(snapshot_str, .type_variable); - try report.document.addLineBreak(); + try report.document.addCodeBlock(snapshot_str); return report; } @@ -2045,8 +2034,7 @@ pub const ReportBuilder = struct { try report.document.addReflowingText(", is:"); try report.document.addLineBreak(); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(snapshot_str, .type_variable); + try report.document.addCodeBlock(snapshot_str); try report.document.addLineBreak(); try report.document.addLineBreak(); @@ -2126,8 +2114,8 @@ pub const ReportBuilder = struct { try report.document.addReflowingText("The type is:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(snapshot_str, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(snapshot_str); try report.document.addLineBreak(); try report.document.addLineBreak(); @@ -2469,8 +2457,8 @@ pub const ReportBuilder = struct { try report.document.addText("Its inferred type is:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(owned_expected, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(owned_expected); return report; } @@ -2511,8 +2499,8 @@ pub const ReportBuilder = struct { try report.document.addAnnotated("unsigned", .emphasized); try report.document.addReflowingText(":"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(owned_expected, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(owned_expected); return report; } @@ -2549,8 +2537,7 @@ pub const ReportBuilder = struct { try report.document.addText("Its inferred type is:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(owned_expected, .type_variable); + try report.document.addCodeBlock(owned_expected); try report.document.addLineBreak(); try report.document.addLineBreak(); try report.document.addReflowingText("Hint: Use a decimal type like "); @@ -2576,8 +2563,7 @@ pub const ReportBuilder = struct { try report.document.addText("Its inferred type is:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(owned_expected, .type_variable); + try report.document.addCodeBlock(owned_expected); try report.document.addLineBreak(); try report.document.addLineBreak(); try report.document.addReflowingText("Hint: Use a larger integer type or "); @@ -2612,8 +2598,8 @@ pub const ReportBuilder = struct { try report.document.addReflowingText("It has the type:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(owned_expected, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(owned_expected); return report; } @@ -2683,8 +2669,8 @@ pub const ReportBuilder = struct { try report.document.addLineBreak(); const expected_type = try report.addOwnedString(self.getFormattedString(types.expected_snapshot)); - try report.document.addText(" "); - try report.document.addAnnotated(expected_type, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(expected_type); try report.document.addLineBreak(); try report.document.addLineBreak(); @@ -2699,9 +2685,8 @@ pub const ReportBuilder = struct { try report.document.addLineBreak(); const actual_type = try report.addOwnedString(self.getFormattedString(types.actual_snapshot)); - try report.document.addText(" "); - try report.document.addAnnotated(actual_type, .type_variable); try report.document.addLineBreak(); + try report.document.addCodeBlock(actual_type); return report; } @@ -2724,9 +2709,7 @@ pub const ReportBuilder = struct { try report.document.addAnnotated("app", .inline_code); try report.document.addReflowingText(" module to have a type alias named:"); try report.document.addLineBreak(); - try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(owned_name, .type_variable); + try report.document.addCodeBlock(owned_name); try report.document.addLineBreak(); try report.document.addLineBreak(); try report.document.addReflowingText("But I could not find it."); @@ -2756,8 +2739,8 @@ pub const ReportBuilder = struct { try report.document.addAnnotated("app", .inline_code); try report.document.addReflowingText(" module to have a exported definition named:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(owned_name, .type_variable); + try report.document.addLineBreak(); + try report.document.addCodeBlock(owned_name); try report.document.addLineBreak(); try report.document.addLineBreak(); try report.document.addReflowingText("But I could not find it."); @@ -2802,8 +2785,8 @@ pub const ReportBuilder = struct { try report.document.addAnnotated("crash", .keyword); try report.document.addText(" happened with this message:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(owned_message, .emphasized); + try report.document.addLineBreak(); + try report.document.addCodeBlock(owned_message); return report; } @@ -2856,8 +2839,8 @@ pub const ReportBuilder = struct { try report.document.addText("The evaluation failed with error:"); try report.document.addLineBreak(); - try report.document.addText(" "); - try report.document.addAnnotated(owned_error_name, .emphasized); + try report.document.addLineBreak(); + try report.document.addCodeBlock(owned_error_name); return report; } diff --git a/src/check/snapshot.zig b/src/check/snapshot.zig index 5fe1d00e02..e7cc57d065 100644 --- a/src/check/snapshot.zig +++ b/src/check/snapshot.zig @@ -276,7 +276,7 @@ pub const Store = struct { // Format this type and store the formatted string type_writer.reset(); - try type_writer.write(var_); + try type_writer.write(var_, .wrap); const formatted = try self.gpa.dupe(u8, type_writer.get()); try self.formatted_strings.put(self.gpa, snapshot_idx, formatted); diff --git a/src/check/test/TestEnv.zig b/src/check/test/TestEnv.zig index 16499df411..0cc1279bf1 100644 --- a/src/check/test/TestEnv.zig +++ b/src/check/test/TestEnv.zig @@ -452,7 +452,7 @@ pub fn assertDefType(self: *TestEnv, target_def_name: []const u8, expected: []co .assign => |assign| { const def_name = idents.getText(assign.ident); if (std.mem.eql(u8, target_def_name, def_name)) { - try self.type_writer.write(ModuleEnv.varFrom(def_idx)); + try self.type_writer.write(ModuleEnv.varFrom(def_idx), .wrap); try testing.expectEqualStrings(expected, self.type_writer.get()); return; } @@ -477,7 +477,7 @@ pub fn assertLastDefType(self: *TestEnv, expected: []const u8) !void { const last_def_idx = defs_slice[defs_slice.len - 1]; const last_def_var = ModuleEnv.varFrom(last_def_idx); - try self.type_writer.write(last_def_var); + try self.type_writer.write(last_def_var, .wrap); try testing.expectEqualStrings(expected, self.type_writer.get()); } @@ -490,7 +490,7 @@ pub fn assertLastDefTypeContains(self: *TestEnv, expected_substring: []const u8) const last_def_idx = defs_slice[defs_slice.len - 1]; const last_def_var = ModuleEnv.varFrom(last_def_idx); - try self.type_writer.write(last_def_var); + try self.type_writer.write(last_def_var, .wrap); const type_str = self.type_writer.get(); if (std.mem.indexOf(u8, type_str, expected_substring) == null) { std.debug.print("Expected type to contain '{s}', but got: {s}\n", .{ expected_substring, type_str }); diff --git a/src/check/test/cross_module_test.zig.bak b/src/check/test/cross_module_test.zig.bak deleted file mode 100644 index 824b9c6cfe..0000000000 --- a/src/check/test/cross_module_test.zig.bak +++ /dev/null @@ -1,222 +0,0 @@ -//! Tests for cross-module type checking functionality. - -const std = @import("std"); -const base = @import("base"); -const types_mod = @import("types"); -const can = @import("can"); -const Check = @import("../Check.zig"); -const TestEnv = @import("./TestEnv.zig"); - -const CIR = can.CIR; -const Var = types_mod.Var; -const Content = types_mod.Content; -const Ident = base.Ident; -const testing = std.testing; -const ModuleEnv = can.ModuleEnv; -const problem = @import("../problem.zig"); -const snapshot = @import("../snapshot.zig"); -const occurs = @import("../occurs.zig"); -const ProblemStore = problem.Store; -const SnapshotStore = snapshot.Store; -const UnifierScratch = @import("../unify.zig").Scratch; -const OccursScratch = occurs.Scratch; -const unify = @import("../unify.zig").unify; - -test "cross-module - check type - monomorphic function passes" { - const source_a = - \\main! : Str -> Str - \\main! = |s| s - ; - var test_env_a = try TestEnv.init("A", source_a); - defer test_env_a.deinit(); - // Str is auto-imported from Builtin module, so it prints as "Str" - try test_env_a.assertLastDefType("Str -> Str"); - - const source_b = - \\import A - \\ - \\main : Str - \\main = A.main!("hello") - ; - var test_env_b = try TestEnv.initWithImport("B", source_b, "A", &test_env_a); - defer test_env_b.deinit(); - // Str is auto-imported from Builtin module, so it prints as "Str" - try test_env_b.assertLastDefType("Str"); -} - -test "cross-module - check type - monomorphic function fails" { - const source_a = - \\main! : Str -> Str - \\main! = |s| s - ; - var test_env_a = try TestEnv.init("A", source_a); - defer test_env_a.deinit(); - try test_env_a.assertLastDefType("Str -> Str"); - - const source_b = - \\import A - \\ - \\main : U8 - \\main = A.main!(1) - ; - var test_env_b = try TestEnv.initWithImport("B", source_b, "A", &test_env_a); - defer test_env_b.deinit(); - try test_env_b.assertOneTypeError("TYPE MISMATCH"); -} - -test "cross-module - check type - polymorphic function passes" { - const source_a = - \\main! : a -> a - \\main! = |s| s - ; - var test_env_a = try TestEnv.init("A", source_a); - defer test_env_a.deinit(); - try test_env_a.assertLastDefType("a -> a"); - - const source_b = - \\import A - \\ - \\main : Str - \\main = A.main!("hello") - ; - var test_env_b = try TestEnv.initWithImport("B", source_b, "A", &test_env_a); - defer test_env_b.deinit(); - // Str is auto-imported from Builtin module, so it prints as "Str" - try test_env_b.assertLastDefType("Str"); -} - -test "cross-module - check type - polymorphic function with multiple uses passes" { - const source_a = - \\main! : a -> a - \\main! = |s| s - ; - var test_env_a = try TestEnv.init("A", source_a); - defer test_env_a.deinit(); - try test_env_a.assertLastDefType("a -> a"); - - const source_b = - \\import A - \\ - \\main : U64 - \\main = { - \\ a = A.main!(10) - \\ b = A.main!(15) - \\ _c = A.main!("Hello") - \\ a + b - \\} - ; - var test_env_b = try TestEnv.initWithImport("B", source_b, "A", &test_env_a); - defer test_env_b.deinit(); - try test_env_b.assertLastDefType("U64"); -} - -test "cross-module - check type - static dispatch" { - const source_a = - \\A := [A(Str)].{ - \\ to_str : A -> Str - \\ to_str = |A.A(val)| val - \\} - ; - var test_env_a = try TestEnv.init("A", source_a); - defer test_env_a.deinit(); - try test_env_a.assertDefType("A.to_str", "A -> Str"); - - const source_b = - \\import A - \\ - \\a_val = A.A("hello") - \\ - \\main = a_val.to_str() - ; - var test_env_b = try TestEnv.initWithImport("B", source_b, "A", &test_env_a); - defer test_env_b.deinit(); - try test_env_b.assertDefType("a_val", "A"); - try test_env_b.assertDefType("main", "Str"); -} - -test "cross-module - check type - static dispatch - no annotation & indirection" { - const source_a = - \\A := [A(Str)].{ - \\ to_str = |A.A(val)| val - \\ to_str2 = |x| x.to_str() - \\} - ; - var test_env_a = try TestEnv.init("A", source_a); - defer test_env_a.deinit(); - try test_env_a.assertDefType("A.to_str", "A -> Str"); - try test_env_a.assertDefType("A.to_str2", "a -> b where [a.to_str : a -> b ]"); - - const source_b = - \\import A - \\ - \\val1 = A.A("hello") - \\val2 = A.A("world") - \\ - \\main = (val1.to_str(), val1.to_str2(), val2.to_str2()) - \\ - ; - var test_env_b = try TestEnv.initWithImport("B", source_b, "A", &test_env_a); - defer test_env_b.deinit(); - try test_env_b.assertDefType("val1", "A"); - try test_env_b.assertDefType("val2", "A"); - try test_env_b.assertDefType("main", "(Str, Str, Str)"); -} - -test "cross-module - check type - opaque types 1" { - const source_a = - \\A :: [A(Str)].{} - ; - var test_env_a = try TestEnv.init("A", source_a); - defer test_env_a.deinit(); - - const source_b = - \\import A - \\ - \\a_val : A.A - \\a_val = A("hello") - ; - var test_env_b = try TestEnv.initWithImport("B", source_b, "A", &test_env_a); - defer test_env_b.deinit(); - try test_env_b.assertFirstTypeError("TYPE MISMATCH"); -} - -test "cross-module - check type - opaque types 2" { - const source_a = - \\A :: [A(Str)].{} - ; - var test_env_a = try TestEnv.init("A", source_a); - defer test_env_a.deinit(); - - const source_b = - \\import A - \\ - \\a_val = A.A("hello") - ; - var test_env_b = try TestEnv.initWithImport("B", source_b, "A", &test_env_a); - defer test_env_b.deinit(); - try test_env_b.assertFirstTypeError("CANNOT USE OPAQUE NOMINAL TYPE"); -} - -test "displayNameIsBetter - shorter names are preferred" { - // Tests the core comparison logic used when multiple imports provide different - // display names for the same type (e.g., `import Foo as F` and `import Foo as Foo`). - // The shortest name wins for error message display. For equal lengths, the - // lexicographically smaller name wins (deterministic regardless of import order). - const displayNameIsBetter = Check.displayNameIsBetter; - - // Shorter is better - try testing.expect(displayNameIsBetter("T", "Type")); - try testing.expect(displayNameIsBetter("AB", "ABC")); - try testing.expect(!displayNameIsBetter("Type", "T")); - try testing.expect(!displayNameIsBetter("ABC", "AB")); - - // Equal length: lexicographically smaller wins - try testing.expect(displayNameIsBetter("Abc", "Bbc")); // 'A' < 'B' - try testing.expect(displayNameIsBetter("Aac", "Abc")); // 'a' < 'b' at position 1 - try testing.expect(!displayNameIsBetter("Bbc", "Abc")); - try testing.expect(!displayNameIsBetter("Abc", "Aac")); - - // Identical strings: no replacement - try testing.expect(!displayNameIsBetter("Same", "Same")); - try testing.expect(!displayNameIsBetter("", "")); -} diff --git a/src/check/test/let_polymorphism_integration_test.zig.bak b/src/check/test/let_polymorphism_integration_test.zig.bak deleted file mode 100644 index a3b830ba60..0000000000 --- a/src/check/test/let_polymorphism_integration_test.zig.bak +++ /dev/null @@ -1,254 +0,0 @@ -//! Integration tests for let-polymorphism that parse, canonicalize, and type-check -//! actual code to ensure polymorphic values work correctly in practice. - -const std = @import("std"); -const base = @import("base"); -const parse = @import("parse"); -const can = @import("can"); -const Check = @import("../Check.zig"); -const TestEnv = @import("./TestEnv.zig"); - -const Can = can.Can; -const ModuleEnv = can.ModuleEnv; -const CanonicalizedExpr = can.Can.CanonicalizedExpr; -const testing = std.testing; -const test_allocator = testing.allocator; - -test "direct polymorphic identity usage" { - const source = - \\{ - \\ id = |x| x - \\ a = id(1) - \\ b = id("x") - \\ { a, b } - \\} - ; - // The field 'a' has the same type as the dispatcher for from_numeral, so they should share the same name - // Note: 'c' is used because 'a' and 'b' are already identifiers in the code - try typeCheck(source, "{ a: c, b: Str } where [c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)])]"); -} - -test "higher-order function with polymorphic identity" { - const source = - \\{ - \\ id = |x| x - \\ f = |g, v| g(v) - \\ a = f(id, 1) - \\ b = f(id, "x") - \\ { a, b } - \\} - ; - try typeCheck(source, "{ a: c, b: Str } where [c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)])]"); -} - -test "let-polymorphism with function composition" { - const source = - \\{ - \\ compose = |f, g| |x| f(g(x)) - \\ double = |x| x * 2 - \\ add_one = |x| x + 1 - \\ num_compose = compose(double, add_one) - \\ result1 = num_compose(5) - \\ { result1 } - \\} - ; - try typeCheck(source, "a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]"); -} - -test "polymorphic empty list" { - const source = - \\{ - \\ empty = [] - \\ nums = [1, 2, 3] - \\ strs = ["a", "b", "c"] - \\ { empty, nums, strs } - \\} - ; - try typeCheck( - source, - \\{ empty: List(_a), nums: List(b), strs: List(Str) } - \\ where [b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])] - , - ); -} - -test "polymorphic cons function" { - const source = - \\{ - \\ cons = |x, xs| List.concat([x], xs) - \\ list1 = cons(1, [2, 3]) - \\ list2 = cons("a", ["b", "c"]) - \\ { list1, list2 } - \\} - ; - try typeCheck( - source, - \\{ list1: List(item), list2: List(Str) } - \\ where [item.from_numeral : Numeral -> Try(item, [InvalidNumeral(Str)])] - , - ); -} - -test "polymorphic record constructor" { - const source = - \\{ - \\ make_pair = |x, y| { first: x, second: y } - \\ pair1 = make_pair(1, "a") - \\ pair2 = make_pair("b", 42) - \\ pair3 = make_pair(True, False) - \\ { pair1, pair2, pair3 } - \\} - ; - try typeCheck( - source, - \\{ pair1: { first: a, second: Str }, pair2: { first: Str, second: b }, pair3: { first: [True, .._others], second: [False, .._others2] } } - \\ where [ - \\ a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - \\ b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - \\ ] - , - ); -} - -test "polymorphic identity with various numeric types" { - const source = - \\{ - \\ id = |x| x - \\ int_val = id(42) - \\ float_val = id(3.14) - \\ bool_val = id(True) - \\ { int_val, float_val, bool_val } - \\} - ; - try typeCheck( - source, - \\{ bool_val: [True, .._others], float_val: a, int_val: b } - \\ where [ - \\ a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - \\ b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - \\ ] - , - ); -} - -test "nested polymorphic data structures" { - const source = - \\{ - \\ make_box = |x| { value: x } - \\ box1 = make_box(42) - \\ box2 = make_box("hello") - \\ nested = make_box(make_box(100)) - \\ { box1, box2, nested } - \\} - ; - try typeCheck( - source, - - \\{ box1: { value: a }, box2: { value: Str }, nested: { value: { value: b } } } - \\ where [ - \\ a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - \\ b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - \\ ] - , - ); -} - -test "polymorphic function in let binding" { - const source = - \\{ - \\ result = { - \\ id = |x| x - \\ a = id(1) - \\ b = id("test") - \\ { a, b } - \\ } - \\ result - \\} - ; - try typeCheck(source, "{ a: c, b: Str } where [c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)])]"); -} - -test "polymorphic swap function" { - const source = - \\{ - \\ swap = |pair| { first: pair.second, second: pair.first } - \\ pair1 = { first: 1, second: "a" } - \\ pair2 = { first: True, second: 42 } - \\ swapped1 = swap(pair1) - \\ swapped2 = swap(pair2) - \\ { swapped1, swapped2 } - \\} - ; - try typeCheck( - source, - \\{ swapped1: { first: Str, second: a }, swapped2: { first: b, second: [True, .._others] } } - \\ where [ - \\ a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - \\ b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - \\ ] - , - ); -} - -test "polymorphic option type simulation" { - const source = - \\{ - \\ none = { tag: "None" } - \\ some = |x| { tag: "Some", value: x } - \\ opt1 = some(42) - \\ opt2 = some("hello") - \\ opt3 = none - \\ { opt1, opt2, opt3 } - \\} - ; - try typeCheck(source, - \\{ opt1: { tag: Str, value: a }, opt2: { tag: Str, value: Str }, opt3: { tag: Str } } - \\ where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])] - ); -} - -test "polymorphic const function" { - const source = - \\{ - \\ const = |x| |_| x - \\ always5 = const(5) - \\ alwaysHello = const("hello") - \\ num = always5(99) - \\ str = alwaysHello(True) - \\ { num, str } - \\} - ; - try typeCheck( - source, - "{ num: a, str: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]", - ); -} - -test "polymorphic pipe function" { - const source = - \\{ - \\ pipe = |x, f| f(x) - \\ double = |n| n * 2 - \\ length = |_s| 5 - \\ num_result = pipe(21, double) - \\ str_result = pipe("hello", length) - \\ { num_result, str_result } - \\} - ; - try typeCheck( - source, - \\{ num_result: a, str_result: b } - \\ where [ - \\ a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - \\ b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - \\ ] - , - ); -} - -/// A unified helper to run the full pipeline: parse, canonicalize, and type-check source code. -fn typeCheck(comptime source_expr: []const u8, expected_type: []const u8) !void { - var test_env = try TestEnv.initExpr("Test", source_expr); - defer test_env.deinit(); - return test_env.assertLastDefType(expected_type); -} diff --git a/src/check/test/num_type_inference_test.zig b/src/check/test/num_type_inference_test.zig index 14ef13a494..b97f2921cc 100644 --- a/src/check/test/num_type_inference_test.zig +++ b/src/check/test/num_type_inference_test.zig @@ -177,13 +177,13 @@ test "numeric literal in comparison unifies with typed operand" { // Check LHS type (should be I64) const lhs_var = ModuleEnv.varFrom(binop.lhs); - try test_env.type_writer.write(lhs_var); + try test_env.type_writer.write(lhs_var, .wrap); const lhs_type = test_env.type_writer.get(); try testing.expectEqualStrings("I64", lhs_type); // Check RHS type (the literal 42 - should also be I64 after unification) const rhs_var = ModuleEnv.varFrom(binop.rhs); - try test_env.type_writer.write(rhs_var); + try test_env.type_writer.write(rhs_var, .wrap); const rhs_type = test_env.type_writer.get(); try testing.expectEqualStrings("I64", rhs_type); @@ -233,7 +233,7 @@ test "polymorphic numeric in list used as List.get index unifies to U64 - regres // Get the type from the expression (the literal 0) const expr_var = ModuleEnv.varFrom(def.expr); - try test_env.type_writer.write(expr_var); + try test_env.type_writer.write(expr_var, .wrap); const expr_type = test_env.type_writer.get(); // After unification with List.get's U64 parameter, should be U64 @@ -241,7 +241,7 @@ test "polymorphic numeric in list used as List.get index unifies to U64 - regres // Also verify the pattern has the same type const pattern_var = ModuleEnv.varFrom(def.pattern); - try test_env.type_writer.write(pattern_var); + try test_env.type_writer.write(pattern_var, .wrap); const pattern_type = test_env.type_writer.get(); try testing.expectEqualStrings("U64", pattern_type); diff --git a/src/check/test/type_checking_integration.zig.bak b/src/check/test/type_checking_integration.zig.bak deleted file mode 100644 index 41e3a61e6e..0000000000 --- a/src/check/test/type_checking_integration.zig.bak +++ /dev/null @@ -1,2754 +0,0 @@ -//! Integration tests for let-polymorphism that parse, canonicalize, and type-check -//! actual code to ensure polymorphic values work correctly in practice. - -const std = @import("std"); -const base = @import("base"); -const parse = @import("parse"); -const can = @import("can"); -const types_mod = @import("types"); -const problem_mod = @import("../problem.zig"); -const Check = @import("../Check.zig"); -const TestEnv = @import("./TestEnv.zig"); - -const Can = can.Can; -const ModuleEnv = can.ModuleEnv; -const CanonicalizedExpr = can.Can.CanonicalizedExpr; -const testing = std.testing; -const test_allocator = testing.allocator; - -// primitives - nums // - -test "check type - num - unbound" { - const source = - \\50 - ; - try checkTypesExpr( - source, - .pass, - "a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]) ]", - ); -} - -test "check type - num - int suffix 1" { - const source = - \\10u8 - ; - try checkTypesExpr(source, .pass, "U8"); -} - -test "check type - num - int suffix 2" { - const source = - \\10i128 - ; - try checkTypesExpr(source, .pass, "I128"); -} - -test "check type - num - int big" { - const source = - \\{ - \\ e : U128 - \\ e = 340282366920938463463374607431768211455 - \\ - \\ e - \\} - ; - try checkTypesExpr(source, .pass, "U128"); -} - -test "check type - num - float" { - const source = - \\10.1 - ; - try checkTypesExpr( - source, - .pass, - "a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]) ]", - ); -} - -test "check type - num - float suffix 1" { - const source = - \\10.1f32 - ; - try checkTypesExpr(source, .pass, "F32"); -} - -test "check type - num - float suffix 2" { - const source = - \\10.1f64 - ; - try checkTypesExpr(source, .pass, "F64"); -} - -test "check type - num - float suffix 3" { - const source = - \\10.1dec - ; - try checkTypesExpr(source, .pass, "Dec"); -} - -// primitives - strs // - -test "check type - str" { - const source = - \\"hello" - ; - try checkTypesExpr(source, .pass, "Str"); -} - -test "check type - str annotation mismatch with number" { - const source = - \\x : I64 - \\x = "hello" - ; - try checkTypesModule(source, .fail, "TYPE MISMATCH"); -} - -test "check type - number annotation mismatch with string" { - const source = - \\x : Str - \\x = 42 - ; - try checkTypesModule(source, .fail, "MISSING METHOD"); -} - -test "check type - i64 annotation with fractional literal passes type checking" { - // Note: Validation of numeric literals (e.g., fractional to integer) happens - // during comptime evaluation, not type checking. This test verifies that - // type checking passes - the actual validation error is caught by comptime eval. - const source = - \\x : I64 - \\x = 3.14 - ; - try checkTypesModule(source, .{ .pass = .last_def }, "I64"); -} - -test "check type - string plus number should fail" { - // Str + number: when we unify Str with numeric flex, the flex's from_numeral constraint - // gets applied to Str. Since Str doesn't have from_numeral, we get MISSING METHOD. - // The plus dispatch on Str also fails with MISSING METHOD. - const source = - \\x = "hello" + 123 - ; - try checkTypesModule(source, .fail_first, "MISSING METHOD"); -} - -test "check type - string plus string should fail (no plus method)" { - const source = - \\x = "hello" + "world" - ; - try checkTypesModule(source, .fail, "MISSING METHOD"); -} - -// binop operand type unification // - -test "check type - binop operands must have same type - I64 plus I32 should fail" { - const source = - \\x = 1i64 + 2i32 - ; - try checkTypesModule(source, .fail, "TYPE MISMATCH"); -} - -test "check type - binop operands must have same type - I64 minus I32 should fail" { - const source = - \\x = 1i64 - 2i32 - ; - try checkTypesModule(source, .fail, "TYPE MISMATCH"); -} - -test "check type - binop operands must have same type - I64 times I32 should fail" { - const source = - \\x = 1i64 * 2i32 - ; - try checkTypesModule(source, .fail, "TYPE MISMATCH"); -} - -test "check type - binop operands must have same type - F64 divide F32 should fail" { - const source = - \\x = 1.0f64 / 2.0f32 - ; - try checkTypesModule(source, .fail, "TYPE MISMATCH"); -} - -test "check type - binop operands same type works - I64 plus I64" { - const source = - \\x = 1i64 + 2i64 - ; - try checkTypesModule(source, .{ .pass = .last_def }, "I64"); -} - -test "check type - binop operands same type works - unbound plus unbound" { - const source = - \\x = 1 + 2 - ; - try checkTypesModule( - source, - .{ .pass = .last_def }, - "a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]) ]", - ); -} - -test "check type - is_eq operands must have same type - I64 eq I32 should fail" { - const source = - \\x = 1i64 == 2i32 - ; - try checkTypesModule(source, .fail, "TYPE MISMATCH"); -} - -test "check type - comparison operands must have same type - I64 lt I32 should fail" { - const source = - \\x = 1i64 < 2i32 - ; - try checkTypesModule(source, .fail, "TYPE MISMATCH"); -} - -// primitives - lists // - -test "check type - list empty" { - const source = - \\[] - ; - try checkTypesExpr(source, .pass, "List(_a)"); -} - -test "check type - list - same elems 1" { - const source = - \\["hello", "world"] - ; - try checkTypesExpr(source, .pass, "List(Str)"); -} - -test "check type - list - same elems 2" { - const source = - \\[100, 200] - ; - try checkTypesExpr( - source, - .pass, - "List(a) where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]) ]", - ); -} - -test "check type - list - 1st elem more specific coreces 2nd elem" { - const source = - \\[100u64, 200] - ; - try checkTypesExpr(source, .pass, "List(U64)"); -} - -test "check type - list - 2nd elem more specific coreces 1st elem" { - const source = - \\[100, 200u32] - ; - try checkTypesExpr(source, .pass, "List(U32)"); -} - -test "check type - list - diff elems 1" { - const source = - \\["hello", 10] - ; - try checkTypesExpr(source, .fail, "MISSING METHOD"); -} - -// number requirements // - -// Skipped: Literal bounds checking is out of scope for poly removal phase -// See POLY_REMOVAL_PLAN.md -test "check type - num - cannot coerce 500 to u8" { - // const source = - // \\[500, 200u8] - // ; - // try checkTypesExpr(source, .fail, "NUMBER DOES NOT FIT IN TYPE"); -} - -// records // - -test "check type - record" { - const source = - \\{ - \\ hello: "Hello", - \\ world: 10, - \\} - ; - try checkTypesExpr(source, .pass, - \\{ hello: Str, world: a } - \\ where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]) ] - ); -} - -// anonymous type equality (is_eq) // - -test "check type - record equality - same records are equal" { - const source = - \\{ x: 1, y: 2 } == { x: 1, y: 2 } - ; - try checkTypesExpr(source, .pass, "Bool"); -} - -test "check type - tuple equality - same tuples are equal" { - const source = - \\(1, 2) == (1, 2) - ; - try checkTypesExpr(source, .pass, "Bool"); -} - -test "check type - empty record equality" { - const source = - \\{} == {} - ; - try checkTypesExpr(source, .pass, "Bool"); -} - -test "check type - record with function field - no is_eq" { - // Records containing functions should not have is_eq because functions don't have is_eq - const source = - \\{ x: 1, f: |a| a + 1 } == { x: 1, f: |a| a + 1 } - ; - try checkTypesExpr(source, .fail, "TYPE DOES NOT SUPPORT EQUALITY"); -} - -test "check type - tuple with function element - no is_eq" { - // Tuples containing functions should not have is_eq because functions don't have is_eq - const source = - \\(1, |a| a) == (1, |a| a) - ; - try checkTypesExpr(source, .fail, "TYPE DOES NOT SUPPORT EQUALITY"); -} - -test "check type - nested record equality" { - // Nested records should type-check as Bool - const source = - \\{ a: { x: 1 }, b: 2 } == { a: { x: 1 }, b: 2 } - ; - try checkTypesExpr(source, .pass, "Bool"); -} - -test "check type - nested tuple equality" { - // Nested tuples should type-check as Bool - const source = - \\((1, 2), 3) == ((1, 2), 3) - ; - try checkTypesExpr(source, .pass, "Bool"); -} - -test "check type - nested record with function - no is_eq" { - // Nested records containing functions should not have is_eq - const source = - \\{ a: { f: |x| x } } == { a: { f: |x| x } } - ; - try checkTypesExpr(source, .fail, "TYPE DOES NOT SUPPORT EQUALITY"); -} - -test "check type - tag union equality" { - // Tag unions should type-check for equality - const source = - \\Ok(1) == Ok(1) - ; - try checkTypesExpr(source, .pass, "Bool"); -} - -test "check type - tag union with function payload - no is_eq" { - // Tag unions with function payloads should not have is_eq - const source = - \\Fn(|x| x) == Fn(|x| x) - ; - try checkTypesExpr(source, .fail, "TYPE DOES NOT SUPPORT EQUALITY"); -} - -test "check type - direct lambda equality - no is_eq" { - // Lambdas/functions should not support equality comparison - const source = - \\(|x| x) == (|y| y) - ; - try checkTypesExpr(source, .fail, "TYPE DOES NOT SUPPORT EQUALITY"); -} - -// anonymous type inequality (desugars to is_eq().not()) // - -test "check type - (a == b) desugars to a.is_eq(b) with unified args" { - // `a == b` desugars to `a.is_eq(b)` with additional constraint that a and b have the same type - const src_binop = - \\|a, b| a == b - ; - - // The binop version unifies a and b, so they have the same type variable - const expected_binop: []const u8 = "c, c -> d where [c.is_eq : c, c -> d]"; - try checkTypesExpr(src_binop, .pass, expected_binop); - - // The direct method call version does NOT unify a and b - const src_direct = - \\|a, b| a.is_eq(b) - ; - const expected_direct: []const u8 = "c, d -> e where [c.is_eq : c, d -> e]"; - try checkTypesExpr(src_direct, .pass, expected_direct); -} - -test "check type - (a != b) desugars to a.is_eq(b).not() with unified args" { - // `a != b` desugars to `a.is_eq(b).not()` with additional constraint that a and b have the same type - const src_binop = - \\|a, b| a != b - ; - - // The binop version unifies a and b, so they have the same type variable - const expected_binop: []const u8 = "c, c -> d where [c.is_eq : c, c -> e, e.not : e -> d]"; - try checkTypesExpr(src_binop, .pass, expected_binop); - - // The direct method call version does NOT unify a and b - const src_direct = - \\|a, b| a.is_eq(b).not() - ; - const expected_direct: []const u8 = "c, d -> e where [c.is_eq : c, d -> f, f.not : f -> e]"; - try checkTypesExpr(src_direct, .pass, expected_direct); -} - -test "check type - record inequality - same records" { - // != desugars to is_eq().not(), result type is whatever not returns - const source = - \\{ x: 1, y: 2 } != { x: 1, y: 2 } - ; - // For concrete types, the constraint resolves to Bool since record.is_eq returns Bool and Bool.not returns Bool - try checkTypesExpr(source, .pass, "Bool"); -} - -test "check type - record inequality - diff records" { - const source = - \\{ x: 1, y: 2 } == { x: 1, z: 2 } - ; - try checkTypesExpr(source, .fail, "TYPE MISMATCH"); -} - -test "check type - tuple inequality" { - const source = - \\(1, 2) != (1, 2) - ; - try checkTypesExpr(source, .pass, "Bool"); -} - -test "check type - record with function field - no inequality" { - // Records containing functions should not support != because they don't have is_eq - const source = - \\{ x: 1, f: |a| a + 1 } != { x: 1, f: |a| a + 1 } - ; - try checkTypesExpr(source, .fail, "TYPE DOES NOT SUPPORT EQUALITY"); -} - -test "check type - tuple with function element - no inequality" { - // Tuples containing functions should not support != because they don't have is_eq - const source = - \\(1, |a| a) != (1, |a| a) - ; - try checkTypesExpr(source, .fail, "TYPE DOES NOT SUPPORT EQUALITY"); -} - -test "check type - direct lambda inequality - no is_eq" { - // Lambdas/functions should not support inequality comparison (requires is_eq) - const source = - \\(|x| x) != (|y| y) - ; - try checkTypesExpr(source, .fail, "TYPE DOES NOT SUPPORT EQUALITY"); -} - -test "check type - tag union inequality" { - const source = - \\Ok(1) != Ok(1) - ; - try checkTypesExpr(source, .pass, "Bool"); -} - -test "check type - tag union with function payload - no inequality" { - // Tag unions with function payloads should not support != because they don't have is_eq - const source = - \\Fn(|x| x) != Fn(|x| x) - ; - try checkTypesExpr(source, .fail, "TYPE DOES NOT SUPPORT EQUALITY"); -} - -// tags // - -test "check type - tag" { - const source = - \\MyTag - ; - try checkTypesExpr(source, .pass, "[MyTag, .._others]"); -} - -test "check type - tag - args" { - const source = - \\MyTag("hello", 1) - ; - try checkTypesExpr( - source, - .pass, - \\[MyTag(Str, a), .._others] - \\ where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]) ] - , - ); -} - -// blocks // - -test "check type - block - return expr" { - const source = - \\{ - \\ "Hello" - \\} - ; - try checkTypesExpr(source, .pass, "Str"); -} - -test "check type - block - implicit empty record" { - const source = - \\{ - \\ _test = "hello" - \\} - ; - try checkTypesExpr(source, .pass, "{}"); -} - -test "check type - block - local value decl" { - const source = - \\{ - \\ test = "hello" - \\ - \\ test - \\} - ; - try checkTypesExpr(source, .pass, "Str"); -} - -// function // - -test "check type - def - value" { - const source = - \\pairU64 = "hello" - ; - try checkTypesModule(source, .{ .pass = .last_def }, "Str"); -} - -test "check type - def - func" { - const source = - \\id = |_| 20 - ; - try checkTypesModule( - source, - .{ .pass = .last_def }, - "_arg -> a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]) ]", - ); -} - -test "check type - def - id without annotation" { - const source = - \\id = |x| x - ; - try checkTypesModule(source, .{ .pass = .last_def }, "a -> a"); -} - -test "check type - def - id with annotation" { - const source = - \\id : a -> a - \\id = |x| x - ; - try checkTypesModule(source, .{ .pass = .last_def }, "a -> a"); -} - -test "check type - def - func with annotation 1" { - const source = - \\id : x -> Str - \\id = |_| "test" - ; - try checkTypesModule(source, .{ .pass = .last_def }, "x -> Str"); -} - -// TODO: This test is currently failing because annotation parsing doesn't correctly handle -// constraint syntax for flex vars -// This needs to be fixed in the annotation parser, but is separate from the numeric literal work. -test "check type - def - func with annotation 2" { - const source = - \\id : x -> _a - \\id = |_| 15 - ; - // The type annotation says _a is unconstrained, but the implementation returns - // a numeric literal which requires from_numeral method. This is a type error. - try checkTypesModule(source, .fail, "MISSING METHOD"); -} - -test "check type - def - nested lambda" { - const source = - \\id = (((|a| |b| |c| a + b + c)(100))(20))(3) - ; - try checkTypesModule( - source, - .{ .pass = .last_def }, - "d where [d.from_numeral : Numeral -> Try(d, [InvalidNumeral(Str)]) ]", - ); -} - -test "check type - def - forward ref" { - const source = - \\run = id1("howdy") - \\ - \\id1 : x -> x - \\id1 = |x| id2(x) - \\ - \\id2 : x -> x - \\id2 = |x| id3(x) - \\ - \\id3 : x -> x - \\id3 = |x| id4(x) - \\ - \\id4 : x -> x - \\id4 = |x| x - \\ - \\id5 : x -> x - \\id5 = |x| x - ; - try checkTypesModule(source, .{ .pass = .{ .def = "run" } }, "Str"); -} - -test "check type - def - nested lambda with wrong annotation" { - - // Currently the below produces two errors instead of just one. - // NOTE: Num(a) syntax is deprecated - this test may need updating when it's re-enabled - const source = - \\curried_add : Num(a), Num(a), Num(a), Num(a) -> Num(a) - \\curried_add = |a| |b| |c| |d| a + b + c + d - ; - try checkTypesModule(source, .fail, "TYPE MISMATCH"); -} - -// calling functions - -test "check type - def - monomorphic id" { - const source = - \\idStr : Str -> Str - \\idStr = |x| x - \\ - \\test = idStr("hello") - ; - try checkTypesModule(source, .{ .pass = .last_def }, "Str"); -} - -test "check type - def - polymorphic id 1" { - const source = - \\id : x -> x - \\id = |x| x - \\ - \\test = id(5) - ; - try checkTypesModule( - source, - .{ .pass = .last_def }, - "x where [x.from_numeral : Numeral -> Try(x, [InvalidNumeral(Str)]) ]", - ); -} - -test "check type - def - polymorphic id 2" { - const source = - \\id : x -> x - \\id = |x| x - \\ - \\test = (id(5), id("hello")) - ; - try checkTypesModule( - source, - .{ .pass = .last_def }, - "(x, Str) where [x.from_numeral : Numeral -> Try(x, [InvalidNumeral(Str)]) ]", - ); -} - -test "check type - def - out of order" { - // Currently errors out in czer - - const source = - \\id_1 : x -> x - \\id_1 = |x| id_2(x) - \\ - \\id_2 : x -> x - \\id_2 = |x| x - \\ - \\test = id_1("Hellor") - ; - try checkTypesModule(source, .{ .pass = .{ .def = "test" } }, "Str"); -} - -test "check type - def - polymorphic higher order 1" { - const source = - \\f = |g, v| g(v) - ; - try checkTypesModule(source, .{ .pass = .last_def }, "(a -> b), a -> b"); -} - -test "check type - top level polymorphic function is generalized" { - const source = - \\id = |x| x - \\ - \\main = { - \\ a = id(42) - \\ _b = id("hello") - \\ a - \\} - ; - try checkTypesModule( - source, - .{ .pass = .last_def }, - "b where [b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]) ]", - ); -} - -test "check type - let-def polymorphic function is generalized" { - const source = - \\main = { - \\ id = |x| x - \\ a = id(42) - \\ _b = id("hello") - \\ a - \\} - ; - try checkTypesModule( - source, - .{ .pass = .last_def }, - "b where [b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]) ]", - ); -} - -test "check type - polymorphic function function param should be constrained" { - const source = - \\id = |x| x - \\ - \\use_twice = |f| { - \\ a = f(42) - \\ b = f("hello") - \\ a - \\} - \\result = use_twice(id) - ; - try checkTypesModule(source, .fail, "MISSING METHOD"); -} - -// type aliases // - -test "check type - basic alias" { - const source = - \\main! = |_| {} - \\ - \\MyAlias : Str - \\ - \\x : MyAlias - \\x = "hello" - ; - try checkTypesModule(source, .{ .pass = .last_def }, "MyAlias"); -} - -test "check type - alias with arg" { - const source = - \\main! = |_| {} - \\ - \\MyListAlias(a) : List(a) - \\ - \\x : MyListAlias(I64) - \\x = [15] - ; - try checkTypesModule(source, .{ .pass = .last_def }, "MyListAlias(I64)"); -} - -test "check type - alias with mismatch arg" { - const source = - \\MyListAlias(a) : List(a) - \\ - \\x : MyListAlias(Str) - \\x = [15] - ; - try checkTypesModule(source, .fail, "MISSING METHOD"); -} - -// nominal types // - -test "check type - basic nominal" { - const source = - \\main! = |_| {} - \\ - \\MyNominal := [MyNominal] - \\ - \\x : MyNominal - \\x = MyNominal.MyNominal - ; - try checkTypesModule(source, .{ .pass = .last_def }, "MyNominal"); -} - -test "check type - nominal with tag arg" { - const source = - \\main! = |_| {} - \\ - \\MyNominal := [MyNominal(Str)] - \\ - \\x : MyNominal - \\x = MyNominal.MyNominal("hello") - ; - try checkTypesModule(source, .{ .pass = .last_def }, "MyNominal"); -} - -test "check type - nominal with type and tag arg" { - const source = - \\main! = |_| {} - \\ - \\MyNominal(a) := [MyNominal(a)] - \\ - \\x : MyNominal(U8) - \\x = MyNominal.MyNominal(10) - ; - try checkTypesModule(source, .{ .pass = .last_def }, "MyNominal(U8)"); -} - -test "check type - nominal with with rigid vars" { - const source = - \\main! = |_| {} - \\ - \\Pair(a) := [Pair(a, a)] - \\ - \\pairU64 : Pair(U64) - \\pairU64 = Pair.Pair(1, 2) - ; - try checkTypesModule(source, .{ .pass = .last_def }, "Pair(U64)"); -} - -test "check type - nominal with with rigid vars mismatch" { - const source = - \\Pair(a) := [Pair(a, a)] - \\ - \\u64val : U64 - \\u64val = 1 - \\ - \\pairU64 : Pair(U64) - \\pairU64 = Pair.Pair(u64val, "Str") - ; - try checkTypesModule(source, .fail, "INVALID NOMINAL TAG"); -} - -test "check type - nominal recursive type" { - const source = - \\main! = |_| {} - \\ - \\ConsList(a) := [Nil, Cons(a, ConsList(a))] - \\ - \\x : ConsList(Str) - \\x = ConsList.Cons("hello", ConsList.Nil) - ; - try checkTypesModule(source, .{ .pass = .last_def }, "ConsList(Str)"); -} - -test "check type - nominal recursive type anno mismatch" { - const source = - \\ConsList(a) := [Nil, Cons(a, ConsList(a))] - \\ - \\x : ConsList(I64) - \\x = ConsList.Cons("hello", ConsList.Nil) - ; - try checkTypesModule(source, .fail, "TYPE MISMATCH"); -} - -test "check type - two nominal types" { - const source = - \\main! = |_| {} - \\ - \\Elem(a) := [Elem(a)] - \\ - \\ConsList(a) := [Nil, Cons(a, ConsList(a))] - \\ - \\x = ConsList.Cons(Elem.Elem("hello"), ConsList.Nil) - ; - try checkTypesModule(source, .{ .pass = .last_def }, "ConsList(Elem(Str))"); -} - -test "check type - nominal recursive type no args" { - const source = - \\main! = |_| {} - \\ - \\StrConsList := [Nil, Cons(Str, StrConsList)] - \\ - \\x : StrConsList - \\x = StrConsList.Cons("hello", StrConsList.Nil) - ; - try checkTypesModule(source, .{ .pass = .last_def }, "StrConsList"); -} - -test "check type - nominal recursive type wrong type" { - const source = - \\StrConsList := [Nil, Cons(Str, StrConsList)] - \\ - \\x : StrConsList - \\x = StrConsList.Cons(10, StrConsList.Nil) - ; - try checkTypesModule(source, .fail, "MISSING METHOD"); -} - -test "check type - nominal w/ polymorphic function with bad args" { - const source = - \\Pair(a) := [Pair(a, a)] - \\ - \\mkPairInvalid : a, b -> Pair(a) - \\mkPairInvalid = |x, y| Pair.Pair(x, y) - ; - try checkTypesModule(source, .fail, "INVALID NOMINAL TAG"); -} - -test "check type - nominal w/ polymorphic function" { - const source = - \\main! = |_| {} - \\ - \\Pair(a, b) : (a, b) - \\ - \\swapPair : Pair(a, b) -> Pair(b, a) - \\swapPair = |(x, y)| (y, x) - \\ - \\test = swapPair((1, "test")) - ; - try checkTypesModule( - source, - .{ .pass = .last_def }, - "Pair(Str, a) where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]) ]", - ); -} - -// bool - -test "check type - bool unqualified" { - const source = - \\x : Bool - \\x = True - ; - try checkTypesModule(source, .{ .pass = .last_def }, "Bool"); -} - -test "check type - bool qualified" { - const source = - \\x = Bool.True - ; - try checkTypesModule(source, .{ .pass = .last_def }, "Bool"); -} - -test "check type - bool lambda" { - const source = - \\x = (|y| !y)(Bool.True) - ; - try checkTypesModule(source, .{ .pass = .last_def }, "Bool"); -} - -// if-else - -test "check type - if else" { - const source = - \\x : Str - \\x = if True "true" else "false" - ; - try checkTypesModule(source, .{ .pass = .last_def }, "Str"); -} - -test "check type - if else - qualified bool" { - const source = - \\x : Str - \\x = if Bool.True "true" else "false" - ; - try checkTypesModule(source, .{ .pass = .last_def }, "Str"); -} - -test "check type - if else - invalid condition 1" { - const source = - \\x : Str - \\x = if 5 "true" else "false" - ; - try checkTypesModule(source, .fail, "MISSING METHOD"); -} - -test "check type - if else - invalid condition 2" { - const source = - \\x : Str - \\x = if 10 "true" else "false" - ; - try checkTypesModule(source, .fail, "MISSING METHOD"); -} - -test "check type - if else - invalid condition 3" { - const source = - \\x : Str - \\x = if "True" "true" else "false" - ; - try checkTypesModule(source, .fail, "INVALID IF CONDITION"); -} - -test "check type - if else - different branch types 1" { - const source = - \\x = if True "true" else 10 - ; - try checkTypesModule(source, .fail, "MISSING METHOD"); -} - -test "check type - if else - different branch types 2" { - const source = - \\x = if True "true" else if False "false" else 10 - ; - try checkTypesModule(source, .fail, "MISSING METHOD"); -} - -test "check type - if else - different branch types 3" { - const source = - \\x = if True "true" else if False 10 else "last" - ; - try checkTypesModule(source, .fail, "MISSING METHOD"); -} - -// match - -test "check type - match" { - const source = - \\x = - \\ match True { - \\ True => "true" - \\ False => "false" - \\ } - ; - try checkTypesModule(source, .{ .pass = .last_def }, "Str"); -} - -test "check type - match - diff cond types 1" { - const source = - \\x = - \\ match "hello" { - \\ True => "true" - \\ False => "false" - \\ } - ; - try checkTypesModule(source, .fail, "INCOMPATIBLE MATCH PATTERNS"); -} - -test "check type - match - diff branch types" { - const source = - \\x = - \\ match True { - \\ True => "true" - \\ False => 100 - \\ } - ; - try checkTypesModule(source, .fail, "MISSING METHOD"); -} - -// unary not - -test "check type - unary not" { - const source = - \\x = !True - ; - try checkTypesModule(source, .{ .pass = .last_def }, "Bool"); -} - -test "check type - unary not mismatch" { - const source = - \\x = !"Hello" - ; - try checkTypesModule(source, .fail, "TYPE MISMATCH"); -} - -// unary not - -test "check type - unary minus" { - const source = - \\x = -10 - ; - try checkTypesModule( - source, - .{ .pass = .last_def }, - "a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]) ]", - ); -} - -test "check type - unary minus mismatch" { - const source = - \\x = "hello" - \\ - \\y = -x - ; - try checkTypesModule(source, .fail, "MISSING METHOD"); -} - -// binops - -test "check type - binops math plus" { - const source = - \\x = 10 + 10u32 - ; - try checkTypesModule(source, .{ .pass = .last_def }, "U32"); -} - -test "check type - binops math sub" { - const source = - \\x = 1 - 0.2 - ; - try checkTypesModule( - source, - .{ .pass = .last_def }, - "a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]) ]", - ); -} - -test "check type - binops ord" { - const source = - \\x = 10.0f32 > 15 - ; - try checkTypesModule(source, .{ .pass = .last_def }, "Bool"); -} - -test "check type - binops and" { - const source = - \\x = True and False - ; - try checkTypesModule(source, .{ .pass = .last_def }, "Bool"); -} - -test "check type - binops and mismatch" { - const source = - \\x = "Hello" and False - ; - try checkTypesModule(source, .fail, "INVALID BOOL OPERATION"); -} - -test "check type - binops or" { - const source = - \\x = True or False - ; - try checkTypesModule(source, .{ .pass = .last_def }, "Bool"); -} - -test "check type - binops or mismatch" { - const source = - \\x = "Hello" or False - ; - try checkTypesModule(source, .fail, "INVALID BOOL OPERATION"); -} - -// record access - -test "check type - record - access" { - const source = - \\r = - \\ { - \\ hello: "Hello", - \\ world: 10, - \\ } - \\ - \\x = r.hello - ; - try checkTypesModule(source, .{ .pass = .last_def }, "Str"); -} - -test "check type - record - access func polymorphic" { - const source = - \\x = |r| r.my_field - ; - try checkTypesModule(source, .{ .pass = .last_def }, "{ my_field: a } -> a"); -} - -test "check type - record - access - not a record" { - const source = - \\r = "hello" - \\ - \\x = r.my_field - ; - try checkTypesModule(source, .fail, "TYPE MISMATCH"); -} - -// record update - -test "check type - record - update 1" { - const source = - \\update_data = |container, new_value| { ..container, data: new_value } - ; - try checkTypesModule( - source, - .{ .pass = .{ .def = "update_data" } }, - "{ ..a, data: b }, b -> { ..a, data: b }", - ); -} - -test "check type - record - update 2" { - const source = - \\set_data = |container, new_value| { ..container, data: new_value } - \\ - \\updated1 = set_data({ data: 10 }, 100) # Updates field - \\updated2 = set_data({ data: 10, other: "hello" }, 100) # Updates with extra fields - \\updated3 = set_data({ data: "hello" }, "world") # Polymorphic - \\ - \\final = (updated1, updated2, updated3) - ; - try checkTypesModule( - source, - .{ .pass = .{ .def = "final" } }, - \\({ data: a }, { data: b, other: Str }, { data: Str }) - \\ where [ - \\ a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - \\ b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - \\ ] - , - ); -} - -test "check type - record - update fail" { - const source = - \\set_data = |container, new_value| { ..container, data: new_value } - \\ - \\updated = set_data({ data: "hello" }, 10) - ; - try checkTypesModule( - source, - .fail, - "MISSING METHOD", - ); -} - -// tags // - -test "check type - patterns - wrong type" { - const source = - \\{ - \\ x = True - \\ - \\ match(x) { - \\ "hello" => "world", - \\ } - \\} - ; - try checkTypesExpr(source, .fail, "INCOMPATIBLE MATCH PATTERNS"); -} - -test "check type - patterns tag without payload" { - const source = - \\{ - \\ x = True - \\ - \\ match(x) { - \\ True => "true", - \\ False => "false", - \\ } - \\} - ; - try checkTypesExpr(source, .pass, "Str"); -} - -test "check type - patterns tag with payload" { - const source = - \\{ - \\ x = Ok("ok") - \\ - \\ match(x) { - \\ Ok(val) => val, - \\ Err(_) => "err", - \\ } - \\} - ; - try checkTypesExpr(source, .pass, "Str"); -} - -test "check type - patterns tag with payload mismatch" { - const source = - \\{ - \\ x = Ok("ok") - \\ - \\ match(x) { - \\ Ok(True) => 10 * 10, - \\ Err(_) => 0, - \\ } - \\} - ; - try checkTypesExpr(source, .fail, "INCOMPATIBLE MATCH PATTERNS"); -} - -test "check type - patterns str" { - const source = - \\{ - \\ x = "hello" - \\ - \\ match(x) { - \\ "world" => "true", - \\ _ => "false", - \\ } - \\} - ; - try checkTypesExpr(source, .pass, "Str"); -} - -test "check type - patterns num" { - const source = - \\{ - \\ x = 10 - \\ - \\ match(x) { - \\ 10 => "true", - \\ _ => "false", - \\ } - \\} - ; - try checkTypesExpr(source, .pass, "Str"); -} - -test "check type - patterns int mismatch" { - const source = - \\{ - \\ x = 10u8 - \\ - \\ match(x) { - \\ 10u32 => "true", - \\ _ => "false", - \\ } - \\} - ; - try checkTypesExpr(source, .fail, "INCOMPATIBLE MATCH PATTERNS"); -} - -test "check type - patterns frac 1" { - const source = - \\{ - \\ match(20) { - \\ 10dec as x => x, - \\ _ => 15, - \\ } - \\} - ; - try checkTypesExpr(source, .pass, "Dec"); -} - -test "check type - patterns frac 2" { - const source = - \\{ - \\ match(10) { - \\ 10f32 as x => x, - \\ _ => 15, - \\ } - \\} - ; - try checkTypesExpr(source, .pass, "F32"); -} - -test "check type - patterns frac 3" { - const source = - \\{ - \\ match(50) { - \\ 10 as x => x, - \\ 15f64 as x => x, - \\ _ => 20, - \\ } - \\} - ; - try checkTypesExpr(source, .pass, "F64"); -} - -test "check type - patterns list" { - const source = - \\{ - \\ x = ["a", "b", "c"] - \\ - \\ match(x) { - \\ [.. as b, _a] => b, - \\ [_a, .. as b] => b, - \\ [] => [], - \\ } - \\} - ; - try checkTypesExpr(source, .pass, "List(Str)"); -} - -test "check type - patterns record" { - const source = - \\{ - \\ val = { x: "hello", y: True } - \\ - \\ match(val) { - \\ { y: False } => "False", - \\ { x } => x, - \\ } - \\} - ; - try checkTypesExpr(source, .pass, "Str"); -} - -test "check type - patterns record 2" { - const source = - \\{ - \\ val = { x: "hello", y: True } - \\ - \\ match(val) { - \\ { y: False, x: "world" } => 10 - \\ _ => 20, - \\ } - \\} - ; - try checkTypesExpr( - source, - .pass, - "a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]) ]", - ); -} - -test "check type - patterns record field mismatch" { - const source = - \\{ - \\ val = { x: "hello" } - \\ - \\ match(val) { - \\ { x: False } => 10 - \\ _ => 20 - \\ } - \\} - ; - try checkTypesExpr(source, .fail, "INCOMPATIBLE MATCH PATTERNS"); -} - -// vars + reassignment // - -test "check type - var ressignment" { - const source = - \\main = { - \\ var x = 1 - \\ x = x + 1 - \\ x - \\} - ; - try checkTypesModule( - source, - .{ .pass = .last_def }, - "a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]) ]", - ); -} - -// expect // - -test "check type - expect" { - const source = - \\main = { - \\ x = 1 - \\ expect x == 1 - \\ x - \\} - ; - // Numeric literals with from_numeral constraints are NOT generalized (GitHub #8666). - // This means constraints from `x == 1` (the is_eq constraint) DO propagate back - // to the definition of x, along with the original from_numeral constraint. - try checkTypesModule( - source, - .{ .pass = .last_def }, - \\a - \\ where [ - \\ a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - \\ a.is_eq : a, a -> Bool, - \\ ] - , - ); -} - -test "check type - expect not bool" { - const source = - \\main = { - \\ x = 1 - \\ expect x - \\ x - \\} - ; - try checkTypesModule(source, .fail, "MISSING METHOD"); -} - -// crash // - -test "check type - crash" { - const source = - \\y : U64 - \\y = { - \\ crash "bug" - \\} - \\ - \\main = { - \\ x = 1 - \\ x + y - \\} - ; - try checkTypesModule( - source, - .{ .pass = .{ .def = "main" } }, - "U64", - ); -} - -// dbg // - -test "check type - dbg" { - // dbg returns {} (not the value it's debugging), so it can be used - // as a statement/side-effect without affecting the block's return type - const source = - \\y : U64 - \\y = { - \\ dbg 2 - \\ 42 - \\} - \\ - \\main = { - \\ x = 1 - \\ x + y - \\} - ; - try checkTypesModule( - source, - .{ .pass = .{ .def = "main" } }, - "U64", - ); -} - -// for // - -test "check type - for" { - const source = - \\main = { - \\ var result = 0 - \\ for x in [1, 2, 3] { - \\ result = result + x - \\ } - \\ result - \\} - ; - try checkTypesModule( - source, - .{ .pass = .{ .def = "main" } }, - "a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]) ]", - ); -} - -test "check type - for mismatch" { - const source = - \\main = { - \\ var result = 0 - \\ for x in ["a", "b", "c"] { - \\ result = result + x - \\ } - \\ result - \\} - ; - try checkTypesModule( - source, - .fail, - "MISSING METHOD", - ); -} - -// static dispatch // - -test "check type - static dispatch - polymorphic - annotation" { - const source = - \\main : a -> Str where [a.to_str : a -> Str] - \\main = |a| a.to_str() - ; - try checkTypesModule( - source, - .{ .pass = .{ .def = "main" } }, - "a -> Str where [a.to_str : a -> Str ]", - ); -} - -test "check type - static dispatch - polymorphic - no annotation" { - const source = - \\main = |x| x.to_str() - ; - try checkTypesModule( - source, - .{ .pass = .{ .def = "main" } }, - "a -> b where [a.to_str : a -> b ]", - ); -} - -test "check type - static dispatch - concrete - annotation" { - const source = - \\Test := [Val(Str)].{ - \\ to_str : Test -> Str - \\ to_str = |Test.Val(s)| s - \\} - \\ - \\main : Str - \\main = Test.Val("hello").to_str() - ; - try checkTypesModule( - source, - .{ .pass = .{ .def = "main" } }, - "Str", - ); -} - -test "check type - static dispatch - concrete - no annotation" { - const source = - \\Test := [Val(Str)].{ - \\ to_str = |Test.Val(s)| s - \\} - \\ - \\main = Test.Val("hello").to_str() - ; - try checkTypesModule( - source, - .{ .pass = .{ .def = "main" } }, - "Str", - ); -} - -test "check type - static dispatch - concrete - wrong method name" { - const source = - \\Test := [Val(Str)].{ - \\ to_str = |Test.Val(s)| s - \\} - \\ - \\main = Test.Val("hello").to_num() - ; - try checkTypesModule( - source, - .fail, - "MISSING METHOD", - ); -} - -test "check type - static dispatch - concrete - args" { - const source = - \\Test := [Val(U8)].{ - \\ add = |Test.Val(a), b| Test.Val(a + b) - \\} - \\ - \\main = Test.Val(1).add(1) - ; - try checkTypesModule( - source, - .{ .pass = .{ .def = "main" } }, - "Test", - ); -} - -test "check type - static dispatch - concrete - wrong args" { - const source = - \\Test := [Val(U8)].{ - \\ add = |Test.Val(a), b| Test.Val(a + b) - \\} - \\ - \\main = Test.Val(1).add("hello") - ; - try checkTypesModule( - source, - .fail, - "TYPE MISMATCH", - ); -} - -test "check type - static dispatch - concrete - indirection 1" { - const source = - \\Test := [Val(Str)].{ - \\ to_str = |Test.Val(s)| s - \\ to_str2 = |test| test.to_str() - \\} - ; - try checkTypesModule( - source, - .{ .pass = .{ .def = "Test.to_str2" } }, - "a -> b where [a.to_str : a -> b ]", - ); -} - -test "check type - static dispatch - concrete - indirection 2" { - const source = - \\main! = |_| {} - \\ - \\Test := [Val(Str)].{ - \\ to_str = |Test.Val(s)| s - \\ to_str2 = |test| test.to_str() - \\} - \\ - \\ - \\func = Test.Val("hello").to_str2() - ; - try checkTypesModule( - source, - .{ .pass = .{ .def = "func" } }, - "Str", - ); -} - -test "check type - static dispatch - fail if not in type signature" { - const source = - \\main! = |_| {} - \\ - \\func : a -> a - \\func = |a| { - \\ _val = a.method() - \\ a - \\} - ; - try checkTypesModule( - source, - .fail, - "MISSING METHOD", - ); -} - -test "check type - static dispatch - let poly" { - const source = - \\main! = |_| {} - \\ - \\process_container : a -> Str where [a.get_or : a, Str -> Str] - \\process_container = |container| { - \\ result = container.get_or("empty") - \\ result - \\} - ; - try checkTypesModule( - source, - .{ .pass = .{ .def = "process_container" } }, - "a -> Str where [a.get_or : a, Str -> Str ]", - ); -} - -test "check type - static dispatch - let poly 2" { - const source = - \\main! = |_| {} - \\ - \\# Define a Container type with methods - \\Container(a) := [Empty, Value(a)].{ - \\ - \\ # Method to get value or provide default - \\ get_or : Container(a), a -> a - \\ get_or = |container, default| { - \\ match container { - \\ Value(val) => val - \\ Empty => default - \\ } - \\ } - \\} - \\ - \\process_container : a -> Str where [a.get_or : a, Str -> Str] - \\process_container = |container| { - \\ result = container.get_or("empty") - \\ result - \\} - \\ - \\func = { - \\ c = Container.Empty - \\ process_container(c) - \\} - ; - try checkTypesModule( - source, - .{ .pass = .{ .def = "func" } }, - "Str", - ); -} - -test "check type - static dispatch - polymorphic type" { - const source = - \\main! = |_| {} - \\ - \\Container(a) := [Value(a)].{ - \\ # Method to map over the contained value - \\ map : Container(a), (a -> b) -> Container(b) - \\ map = |Value(val), f| { - \\ Value(f(val)) - \\ } - \\} - ; - try checkTypesModule( - source, - .{ .pass = .{ .def = "Test.Container.map" } }, - "Container(a), (a -> b) -> Container(b)", - ); -} - -test "check type - static dispatch - polymorphic type 2" { - const source = - \\Container(a) := [Value(a)].{ - \\ # Method to map over the contained value - \\ map : Container(a), (a -> b) -> Container(b) - \\ map = |c, f| { - \\ match c { - \\ Value(val) => Value(f(val)) - \\ } - \\ } - \\} - \\ - \\main! = |_| {} - ; - try checkTypesModule( - source, - .{ .pass = .{ .def = "Test.Container.map" } }, - "Container(a), (a -> b) -> Container(b)", - ); -} - -test "check type - static dispatch - polymorphic type 3" { - const source = - \\Container(a) := [Empty, Value(a)].{ - \\ # Method to map over the contained value - \\ map : Container(a), (a -> b) -> Container(b) - \\ map = |container, f| { - \\ match container { - \\ Value(val) => Value(f(val)) - \\ Empty => Empty - \\ } - \\ } - \\} - \\ - \\main! = |_| {} - ; - try checkTypesModule( - source, - .{ .pass = .{ .def = "Test.Container.map" } }, - "Container(a), (a -> b) -> Container(b)", - ); -} - -// comprehensive // - -test "check type - comprehensive - multiple layers of let-polymorphism" { - const source = - \\main! = |_| {} - \\ - \\# First layer: polymorphic identity - \\id : a -> a - \\id = |x| x - \\ - \\# Second layer: uses id polymorphically multiple times - \\apply_twice : (a -> a), a -> a - \\apply_twice = |f, x| { - \\ first = f(x) - \\ second = f(first) - \\ second - \\} - \\ - \\# Third layer: uses apply_twice with different types - \\func = { - \\ num_result = apply_twice(id, 42) - \\ str_result = apply_twice(id, "hello") - \\ bool_result = apply_twice(id, Bool.True) - \\ (num_result, str_result, bool_result) - \\} - ; - try checkTypesModule( - source, - .{ .pass = .{ .def = "func" } }, - "(a, Str, Bool) where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]) ]", - ); -} - -test "check type - comprehensive - multiple layers of lambdas" { - const source = - \\main! = |_| {} - \\ - \\# Four layers of nested lambdas - \\curried_add : a, a, a, a -> a where [a.add : a, a -> a] - \\curried_add = |a, b, c, d| a + b + c + d - \\ - \\func = { - \\ step1 = curried_add(1, 2, 3, 4) - \\ step1 - \\} - ; - try checkTypesModule( - source, - .{ .pass = .{ .def = "func" } }, - "a where [a.add : a, a -> a, a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]) ]", - ); -} - -test "check type - comprehensive - static dispatch with multiple methods" { - const source = - \\main! = |_| {} - \\ - \\# Define a polymorphic container with static dispatch - \\Container(a) := [Empty, Value(a)].{ - \\ # Method with annotation - \\ map : Container(a), (a -> b) -> Container(b) - \\ map = |container, f| { - \\ match container { - \\ Value(val) => Value(f(val)) - \\ Empty => Empty - \\ } - \\ } - \\ - \\ # Method without annotation (inferred) - \\ get_or = |container, default| { - \\ match container { - \\ Container.Value(val) => val - \\ Empty => default - \\ } - \\ } - \\ - \\ # Chained method dispatch - \\ flat_map : Container(a), (a -> Container(b)) -> Container(b) - \\ flat_map = |container, f| { - \\ match container { - \\ Value(val) => f(val) - \\ Empty => Empty - \\ } - \\ } - \\} - \\ - \\func = { - \\ num_container = Container.Value(100) - \\ - \\ chained = num_container - \\ .map(|x| x + 1) - \\ .flat_map(|x| Container.Value(x + 2)) - \\ .get_or(0) - \\ - \\ chained - \\} - ; - try checkTypesModule( - source, - .{ .pass = .{ .def = "func" } }, - "a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]) ]", - ); -} - -test "check type - comprehensive - static dispatch with multiple methods 2" { - const source = - \\main! = |_| {} - \\ - \\Container(a) := [Empty, Value(a)].{ - \\ mapAdd5 = |container| { - \\ container - \\ .mapAdd4() - \\ .mapAdd1() - \\ } - \\ - \\ mapAdd4 = |container| { - \\ container - \\ .mapAdd2() - \\ .mapAdd2() - \\ } - \\ - \\ mapAdd3 = |container| { - \\ container - \\ .mapAdd2() - \\ .mapAdd1() - \\ } - \\ - \\ mapAdd2 = |container| { - \\ container - \\ .mapAdd1() - \\ .mapAdd1() - \\ } - \\ - \\ mapAdd1 = |container| { - \\ container.map(|val| val + 1) - \\ } - \\ - \\ map : Container(a), (a -> b) -> Container(b) - \\ map = |container, f| { - \\ match container { - \\ Value(val) => Value(f(val)) - \\ Empty => Empty - \\ } - \\ } - \\} - \\ - \\func = { - \\ num_container = Container.Value(100) - \\ num_container.mapAdd5() - \\} - ; - try checkTypesModule( - source, - .{ .pass = .{ .def = "func" } }, - "Container(b) where [b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]) ]", - ); -} - -// Minimal reproduction test cases for segfault -test "check type - segfault minimal 1 - just annotated plus" { - const source = - \\main! = |_| {} - \\ - \\my_plus : a, a -> a where [a.plus : a, a -> a] - \\my_plus = |x, y| x + y - \\ - \\func = my_plus(1u32, 2u32) - ; - try checkTypesModule( - source, - .{ .pass = .{ .def = "func" } }, - "U32", - ); -} - -test "check type - segfault minimal 2 - plus with inferred caller" { - const source = - \\main! = |_| {} - \\ - \\my_plus : a, a -> a where [a.plus : a, a -> a] - \\my_plus = |x, y| x + y - \\ - \\add_two = |a, b| my_plus(a, b) - \\ - \\func = add_two(1u32, 2u32) - ; - try checkTypesModule( - source, - .{ .pass = .{ .def = "func" } }, - "U32", - ); -} - -test "check type - segfault minimal 3a - nested direct - SEGFAULTS" { - const source = - \\main! = |_| {} - \\ - \\my_plus : a, a -> a where [a.plus : a, a -> a] - \\my_plus = |x, y| x + y - \\ - \\func = my_plus(my_plus(1u32, 2u32), 3u32) - ; - try checkTypesModule( - source, - .{ .pass = .{ .def = "func" } }, - "U32", - ); -} - -test "check type - segfault minimal 3b - nested in lambda - SEGFAULTS" { - const source = - \\main! = |_| {} - \\ - \\my_plus : a, a -> a where [a.plus : a, a -> a] - \\my_plus = |x, y| x + y - \\ - \\add_three = |a, b, c| my_plus(my_plus(a, b), c) - \\ - \\func = add_three(1u32, 2u32, 3u32) - ; - try checkTypesModule( - source, - .{ .pass = .{ .def = "func" } }, - "U32", - ); -} - -test "check type - segfault minimal 4 - full original - SEGFAULTS" { - const source = - \\main! = |_| {} - \\ - \\# Annotated function - \\add : a, a -> a where [a.plus : a, a -> a] - \\add = |x, y| x + y - \\ - \\# Inferred function that uses annotated one - \\add_three = |a, b, c| add(add(a, b), c) - \\ - \\# Annotated function using inferred one - \\compute : U32 -> U32 - \\compute = |x| add_three(x, 1u32, 2u32) - \\ - \\func = compute(10u32) - ; - try checkTypesModule( - source, - .{ .pass = .{ .def = "func" } }, - "U32", - ); -} - -test "check type - comprehensive: polymorphism + lambdas + dispatch + annotations" { - const source = - \\main! = |_| {} - \\ - \\# Define a polymorphic container with static dispatch - \\Container(a) := [Empty, Value(a)].{ - \\ # Method with annotation - \\ map : Container(a), (a -> b) -> Container(b) - \\ map = |container, f| { - \\ match container { - \\ Value(val) => Value(f(val)) - \\ Empty => Empty - \\ } - \\ } - \\ - \\ # Method without annotation (inferred) - \\ get_or = |container, default| { - \\ match container { - \\ Value(val) => val - \\ Empty => default - \\ } - \\ } - \\ - \\ # Chained method dispatch - \\ flat_map : Container(a), (a -> Container(b)) -> Container(b) - \\ flat_map = |container, f| { - \\ match container { - \\ Value(val) => f(val) - \\ Empty => Empty - \\ } - \\ } - \\} - \\ - \\# First layer: polymorphic helper with annotation - \\compose : (b -> c), (a -> b), a -> c - \\compose = |g, f, x| g(f(x)) - \\ - \\# Second layer: inferred polymorphic function using compose - \\transform_twice = |f, x| { - \\ first = compose(f, f, x) - \\ second = compose(f, f, first) - \\ second - \\} - \\ - \\# Third layer: curried function (multiple lambda layers) - \\make_processor : (a -> b) -> ((b -> c) -> (a -> c)) - \\make_processor = |f1| |f2| |x| { - \\ step1 = f1(x) - \\ step2 = f2(step1) - \\ step2 - \\} - \\ - \\# Fourth layer: polymorphic function using static dispatch - \\process_with_method : a, c -> d where [a.map : a, (b -> c) -> d] - \\process_with_method = |container, value| { - \\ # Multiple nested lambdas with let-polymorphism - \\ id = |x| x - \\ - \\ result = container.map(|_| id(value)) - \\ result - \\} - \\ - \\# Fifth layer: combine everything - \\main = { - \\ # Let-polymorphism layer 1 - \\ # TODO INLINE ANNOS - \\ # id : a -> a - \\ id = |x| x - \\ - \\ # Let-polymorphism layer 2 with nested lambdas - \\ _apply_to_container = |f| |container| |default| { - \\ mapped = container.map(f) - \\ mapped.get_or(default) - \\ } - \\ - \\ # Create containers - \\ num_container = Container.Value(100) - \\ str_container = Container.Value("hello") - \\ _empty_container = Container.Empty - \\ - \\ # Use id polymorphically on different types - \\ id_num = id(42) - \\ id_str = id("world") - \\ id_bool = id(Bool.True) - \\ - \\ # Multiple layers of curried application - \\ add_ten = |x| x + 10 - \\ processor = make_processor(add_ten)(add_ten) - \\ processed = processor(5) - \\ - \\ # Static dispatch with polymorphic methods - \\ num_result = num_container.map(|x| x + 1) - \\ _str_result = str_container.map(|s| s) - \\ - \\ # Chain method calls with static dispatch - \\ chained = num_container - \\ .map(|x| x + 1) - \\ .flat_map(|x| Container.Value(x + 2)) - \\ .get_or(0) - \\ - \\ # Use transform_twice with let-polymorphism - \\ double_fn = |x| x + x - \\ transformed = transform_twice(double_fn, 3) - \\ - \\ # Final result combining all techniques - \\ { - \\ id_results: (id_num, id_str, id_bool), - \\ processed: processed, - \\ chained: chained, - \\ transformed: transformed, - \\ final: num_result.get_or(0), - \\ } - \\} - ; - try checkTypesModule( - source, - .{ .pass = .{ .def = "main" } }, - \\{ chained: b, final: b, id_results: (e, Str, Bool), processed: c, transformed: a } - \\ where [ - \\ a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - \\ b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - \\ b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - \\ c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)]), - \\ e.from_numeral : Numeral -> Try(e, [InvalidNumeral(Str)]), - \\ ] - , - ); -} - -// scoped type variables - -test "check type - scoped type variables - pass" { - const source = - \\main! = |_| {} - \\ - \\pass : a -> a - \\pass = |x| { - \\ inner : a -> a - \\ inner = |y| y - \\ - \\ inner(x) - \\} - ; - try checkTypesModule( - source, - .{ .pass = .{ .def = "pass" } }, - "a -> a", - ); -} - -test "check type - scoped type variables - fail" { - const source = - \\main! = |_| {} - \\ - \\fail : a -> a - \\fail = |x| { - \\ g : b -> b - \\ g = |z| z - \\ - \\ result : c - \\ result = g(x) - \\ - \\ result - \\} - ; - try checkTypesModule( - source, - .fail, - "TYPE MISMATCH", - ); -} - -test "check type - scoped type variables - bigger example 1" { - const source = - \\test_scoped : a, b -> a - \\test_scoped = |a, b| { - \\ f : a -> a - \\ f = |z| z - \\ - \\ # No err because we correctly provide `a` as the arg - \\ result : a - \\ result = f(a) - \\ - \\ # Err because we incorrectly provide `b` as the arg - \\ _result2 : b - \\ _result2 = f(b) - \\ - \\ result - \\} - ; - try checkTypesModule( - source, - .fail, - "TYPE MISMATCH", - ); -} - -test "check type - scoped type variables - bigger example 2" { - const source = - \\test : val -> val - \\test = |a| { - \\ b : other_val -> other_val - \\ b = |c| { - \\ d : other_val - \\ d = c - \\ - \\ d - \\ } - \\ - \\ b(a) - \\} - ; - try checkTypesModule( - source, - .{ .pass = .{ .def = "test" } }, - "val -> val", - ); -} - -// Associated items referencing each other - -test "associated item can reference another associated item from same type" { - // First verify Bool basics work - const bool_basics = - \\Test := [].{} - \\ - \\x : Bool - \\x = True - ; - try checkTypesModule(bool_basics, .{ .pass = .{ .def = "x" } }, "Bool"); - - // Now test calling MyBool.my_not from within an associated item - const source = - \\Test := [].{ - \\ MyBool := [MyTrue, MyFalse].{ - \\ my_not : MyBool -> MyBool - \\ my_not = |b| match b { - \\ MyTrue => MyFalse - \\ MyFalse => MyTrue - \\ } - \\ - \\ my_eq : MyBool, MyBool -> MyBool - \\ my_eq = |a, b| match a { - \\ MyTrue => b - \\ MyFalse => MyBool.my_not(b) - \\ } - \\ } - \\} - \\ - \\x = Test.MyBool.my_eq(Test.MyBool.MyTrue, Test.MyBool.MyFalse) - ; - try checkTypesModule(source, .{ .pass = .{ .def = "x" } }, "Test.MyBool"); -} - -test "Bool.not works as builtin associated item" { - const source = - \\Test := [].{} - \\ - \\x = Bool.not(True) - ; - try checkTypesModule(source, .{ .pass = .{ .def = "x" } }, "Bool"); -} - -test "Str.is_empty works as low-level builtin associated item" { - const source = - \\Test := [].{} - \\ - \\x = Str.is_empty("") - ; - try checkTypesModule(source, .{ .pass = .{ .def = "x" } }, "Bool"); -} - -test "List.fold works as builtin associated item" { - const source = - \\Test := [].{} - \\ - \\x = List.fold([1, 2, 3], 0, |acc, item| acc + item) - ; - try checkTypesModule(source, .{ .pass = .{ .def = "x" } }, "item where [item.from_numeral : Numeral -> Try(item, [InvalidNumeral(Str)]) ]"); -} - -test "associated item: type annotation followed by body should not create duplicate definition" { - const source = - \\Test := [].{ - \\ apply : (a -> b), a -> b - \\ apply = |fn, x| fn(x) - \\} - \\ - \\result = Test.apply(|n| n, 42) - ; - - var test_env = try TestEnv.init("Test", source); - defer test_env.deinit(); - - // Should have NO errors - the type annotation should be associated with the body - const can_diagnostics = try test_env.module_env.getDiagnostics(); - defer test_env.gpa.free(can_diagnostics); - const type_problems = test_env.checker.problems.problems.items; - - try testing.expectEqual(@as(usize, 0), can_diagnostics.len); - try testing.expectEqual(@as(usize, 0), type_problems.len); - - // Verify the types - try test_env.assertDefType("Test.apply", "(a -> b), a -> b"); - try test_env.assertDefType("result", "b where [b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]) ]"); -} - -// TODO: Move this test to can -test "top-level: type annotation followed by body should not create duplicate definition - REGRESSION TEST" { - // This reproduces the bug seen in test/snapshots/pass/underscore_in_regular_annotations.md - // and test/snapshots/type_function_simple.md where a type annotation followed by its body - // creates TWO defs: - // 1. A def with e-anno-only for the annotation - // 2. A def with the actual lambda body - // This causes a DUPLICATE DEFINITION error - // - // NOTE: Using EXACT code from the snapshot that shows the bug! - const source = - \\app [main!] { pf: platform "platform.roc" } - \\ - \\apply : (_a -> _b) -> _a -> _b - \\apply = |fn, x| fn(x) - \\ - \\main! = |_| {} - ; - - var test_env = try TestEnv.init("Test", source); - defer test_env.deinit(); - - // Check for canonicalization problems - should be specifically DUPLICATE DEFINITION - const can_diagnostics = try test_env.module_env.getDiagnostics(); - defer test_env.gpa.free(can_diagnostics); - - var duplicate_def_found = false; - for (can_diagnostics) |diagnostic| { - var report = try test_env.module_env.diagnosticToReport(diagnostic, test_env.gpa, test_env.module_env.module_name); - defer report.deinit(); - - if (std.mem.indexOf(u8, report.title, "DUPLICATE DEFINITION") != null) { - duplicate_def_found = true; - break; - } - } - - // The bug causes a DUPLICATE DEFINITION error - this test should FAIL when bug is present - if (duplicate_def_found) { - return error.TestUnexpectedResult; - } -} - -// equirecursive static dispatch // - -test "check type - equirecursive static dispatch" { - // Tests that method dispatch works with numeric literals - // The expression (|x| x.plus(5))(7) should type-check successfully - const source = "(|x| x.plus(5))(7)"; - - try checkTypesExpr( - source, - .pass, - "_a", - ); -} - -test "check type - equirecursive static dispatch with type annotation" { - // This tests the exact pattern from the example (|x| x.plus(b))(a) - // but with explicit type annotations. - // This demonstrates that the RecursionVar infrastructure works correctly - // with the same constraint structure as the motivating example. - const source = - \\fn : a, b -> ret where [ - \\ a.plus : a, b -> ret, - \\ a.from_int_digits : List(U8) -> Try(a, [OutOfRange]), - \\ b.from_int_digits : List(U8) -> Try(b, [OutOfRange]) - \\] - \\fn = |a, b| (|x| x.plus(b))(a) - ; - - // The annotated type should match the inferred type - try checkTypesModule( - source, - .{ .pass = .{ .def = "fn" } }, - \\a, b -> ret - \\ where [ - \\ a.from_int_digits : List(U8) -> Try(a, [OutOfRange]), - \\ a.plus : a, b -> ret, - \\ b.from_int_digits : List(U8) -> Try(b, [OutOfRange]), - \\ ] - , - ); -} - -test "check type - static dispatch method type mismatch - REGRESSION TEST" { - // This test verifies that when a method is called with mismatched types, - // we get a TYPE MISMATCH error. This is a regression test for the diagnostic - // output when static dispatch method arguments don't match. - // - // The scenario: a function requires is_eq on type `a`, but we call it - // with two different types (number and string), causing a type mismatch. - const source = - \\fn : a, a -> Bool where [a.is_eq : a, a -> Bool] - \\fn = |x, y| x.is_eq(y) - \\ - \\result = fn(1u64, 2u64) == fn(3u64, 4u64) - ; - - // This should pass - both calls use the same types - try checkTypesModule(source, .{ .pass = .last_def }, "Bool"); -} - -// helpers - module // - -const ModuleExpectation = union(enum) { - pass: DefExpectation, - fail, - fail_first, // Allows multiple errors, checks first error title -}; - -const DefExpectation = union(enum) { - last_def, - def: []const u8, -}; - -/// A unified helper to run the full pipeline: parse, canonicalize, and type-check source code. -/// -/// Behavior depends on the expectation: -/// Pass: Asserts whole module type checks, and assert the specified def matches the expected type string -/// Fail: Asserts that there is exactly 1 type error in the module and it's title matches the expected string -fn checkTypesModule( - comptime source_expr: []const u8, - comptime expectation: ModuleExpectation, - comptime expected: []const u8, -) !void { - var test_env = try TestEnv.init("Test", source_expr); - defer test_env.deinit(); - - switch (expectation) { - .pass => |def_expectation| { - switch (def_expectation) { - .last_def => { - return test_env.assertLastDefType(expected); - }, - .def => |def_name| { - return test_env.assertDefType(def_name, expected); - }, - } - }, - .fail => { - return test_env.assertOneTypeError(expected); - }, - .fail_first => { - return test_env.assertFirstTypeError(expected); - }, - } - - return test_env.assertLastDefType(expected); -} - -// helpers - expr // - -const ExprExpectation = union(enum) { - pass, - fail, -}; - -/// A unified helper to run the full pipeline: parse, canonicalize, and type-check source code. -/// -/// Behavior depends on the expectation: -/// Pass: Asserts expr type checks, and asserts that the expr's type match the expected type string -/// Fail: Asserts that there is exactly 1 type error and it's title matches the expected string -fn checkTypesExpr( - comptime source_expr: []const u8, - comptime expectation: ExprExpectation, - comptime expected: []const u8, -) !void { - var test_env = try TestEnv.initExpr("Test", source_expr); - defer test_env.deinit(); - - switch (expectation) { - .pass => { - return test_env.assertLastDefType(expected); - }, - .fail => { - return test_env.assertOneTypeError(expected); - }, - } - - return test_env.assertLastDefType(expected); -} - -// effectful function type annotation parsing // - -test "check type - effectful zero-arg function annotation" { - // This test verifies that () => {} is parsed as a zero-arg effectful function, - // NOT as a function taking a unit tuple argument. - // The bug was that () => {} was being parsed as (()) => {} - a function taking - // one empty-tuple argument instead of zero arguments. - const source = - \\foo : (() => {}) - \\foo = || {} - ; - // Expected: zero-arg effectful function returning empty record - // If the parser bug exists, this would fail with TYPE MISMATCH because: - // - annotation parses as: (()) => {} (one empty-tuple arg) - // - lambda infers as: ({}) -> {} (zero args, pure) - try checkTypesModule(source, .{ .pass = .last_def }, "({}) => { }"); -} - -test "check type - pure zero-arg function annotation" { - // This test verifies that () -> {} is parsed as a zero-arg pure function, - // NOT as a function taking a unit tuple argument. - const source = - \\foo : (() -> {}) - \\foo = || {} - ; - // Expected: zero-arg pure function returning empty record - try checkTypesModule(source, .{ .pass = .last_def }, "({}) -> { }"); -} - -test "qualified imports don't produce MODULE NOT FOUND during canonicalization" { - // Qualified imports (e.g., "json.Json") are cross-package imports that are - // resolved by the workspace resolver, not during canonicalization. - // They should NOT produce MODULE NOT FOUND errors during canonicalization. - // - // Source from test/snapshots/can_import_comprehensive.md - const source = - \\import json.Json - \\import http.Client as Http exposing [get, post] - \\import utils.String as Str - \\ - \\main = { - \\ client = Http.get - \\ parser = Json.utf8 - \\ helper = Str.trim - \\ - \\ # Test direct module access - \\ result1 = Json.parse - \\ - \\ # Test aliased module access - \\ result2 = Http.post - \\ - \\ # Test exposed items (should work without module prefix) - \\ result3 = get - \\ result4 = post - \\ - \\ # Test multiple qualified access - \\ combined = Str.concat( - \\ client, - \\ parser, - \\ helper, - \\ result1, - \\ result2, - \\ result3, - \\ result4, - \\ combined, - \\ ) - \\} - ; - - var test_env = try TestEnv.init("Test", source); - defer test_env.deinit(); - - const diagnostics = try test_env.module_env.getDiagnostics(); - defer test_env.gpa.free(diagnostics); - - // Count MODULE NOT FOUND errors - var module_not_found_count: usize = 0; - for (diagnostics) |diag| { - if (diag == .module_not_found) { - module_not_found_count += 1; - } - } - - // Qualified imports (json.Json, http.Client, utils.String) should NOT produce - // MODULE NOT FOUND errors - they're handled by the workspace resolver - try testing.expectEqual(@as(usize, 0), module_not_found_count); -} - -// Try with match and error propagation // - -test "check type - try return with match and error propagation should type-check" { - // This tests that a function returning Try(Str, _) with a wildcard error type - // should accept both error propagation (?) and explicit Err tags in match branches. - // The wildcard _ in the return type annotation should unify with any error type. - const source = - \\get_greeting : {} -> Try(Str, _) - \\get_greeting = |{}| { - \\ match 0 { - \\ 0 => Try.Ok(List.first(["hello"])?), - \\ _ => Err(Impossible) - \\ } - \\} - ; - // Expected: should pass type-checking with combined error type (open tag union) - try checkTypesModule(source, .{ .pass = .last_def }, "{ } -> Try(Str, [ListWasEmpty, Impossible, .._others2])"); -} - -// record extension in type annotations // - -test "check type - record extension - basic open record annotation" { - // Test that a function accepting { name: Str, ..others } can take records with extra fields - const source = - \\getName : { name: Str, ..others } -> Str - \\getName = |record| record.name - ; - try checkTypesModule(source, .{ .pass = .last_def }, "{ ..others, name: Str } -> Str"); -} - -test "check type - record extension - closed record satisfies open record" { - // A closed record { name: Str, age: I64 } should satisfy { name: Str, ..others } - const source = - \\getName : { name: Str, ..others } -> Str - \\getName = |record| record.name - \\ - \\result = getName({ name: "Alice", age: 30 }) - ; - try checkTypesModule(source, .{ .pass = .last_def }, "Str"); -} - -test "check type - record extension - multiple fields with extension" { - // Test with multiple required fields and an extension - const source = - \\getFullName : { first: Str, last: Str, ..others } -> Str - \\getFullName = |record| Str.concat(Str.concat(record.first, " "), record.last) - ; - try checkTypesModule(source, .{ .pass = .last_def }, "{ ..others, first: Str, last: Str } -> Str"); -} - -test "check type - record extension - nested records with extension" { - // Test record extension with nested record types - const source = - \\getPersonName : { person: { name: Str, ..inner }, ..outer } -> Str - \\getPersonName = |record| record.person.name - ; - try checkTypesModule(source, .{ .pass = .last_def }, "{ ..outer, person: { ..inner, name: Str } } -> Str"); -} - -test "check type - record extension - empty record with extension" { - // An empty record with extension means "any record" - const source = - \\takeAnyRecord : { ..others } -> Str - \\takeAnyRecord = |_record| "got a record" - ; - try checkTypesModule(source, .{ .pass = .last_def }, "{ ..others } -> Str"); -} - -test "check type - record extension - mismatch should fail" { - // Test that a record missing a required field should fail - const source = - \\getName : { name: Str, ..others } -> Str - \\getName = |record| record.name - \\ - \\result = getName({ age: 30 }) - ; - try checkTypesModule(source, .fail, "TYPE MISMATCH"); -} - -// List method syntax tests - -test "check type - List.get method syntax" { - // Check what type is inferred for [1].get(0) (this works at runtime) - const source = - \\result = [1].get(0) - ; - try checkTypesModule( - source, - .{ .pass = .last_def }, - \\Try(item, [OutOfBounds, ..others]) - \\ where [item.from_numeral : Numeral -> Try(item, [InvalidNumeral(Str)]) ] - , - ); -} - -// List.first method syntax tests - REGRESSION TEST for cycle detection bug - -test "check type - List.first method syntax should not create cyclic types" { - // REGRESSION TEST: This test reproduces a bug where calling [1].first() (method syntax) - // would cause an infinite loop in layout computation because the interpreter was creating - // cyclic rigid var mappings in the TypeScope when building layouts. - // - // The bug: method syntax creates a StaticDispatchConstraint on a flex var. - // When the return type is Try(item, [ListWasEmpty, ..others]) with an open tag union, - // the interpreter was creating cyclic rigid -> rigid mappings in the empty_scope TypeScope. - // - // Method syntax: [1].first() - // Should have same type as function syntax: List.first([1]) - // - // NOTE: The type checking itself is correct - this test verifies type checking produces - // the right type. The bug manifests in the interpreter's layout computation phase. - const source = - \\result = [1].first() - ; - // Expected: Try(item, [ListWasEmpty, ..others]) with item having from_numeral constraint - try checkTypesModule( - source, - .{ .pass = .last_def }, - \\Try(item, [ListWasEmpty, ..others]) - \\ where [item.from_numeral : Numeral -> Try(item, [InvalidNumeral(Str)]) ] - , - ); -} diff --git a/src/check/test/unify_test.zig b/src/check/test/unify_test.zig index 49469b1750..77a78c2ed2 100644 --- a/src/check/test/unify_test.zig +++ b/src/check/test/unify_test.zig @@ -1884,7 +1884,7 @@ test "type_writer - recursion_var displays structure" { var writer = try TypeWriter.initFromParts(gpa, &env.module_env.types, env.module_env.getIdentStore(), null); defer writer.deinit(); - const result = try writer.writeGet(rec_var); + const result = try writer.writeGet(rec_var, .wrap); // Should display as "{}" (the structure it points to) try std.testing.expectEqualStrings("{}", result); @@ -1919,7 +1919,7 @@ test "type_writer - recursion_var with cycle displays correctly" { var writer = try TypeWriter.initFromParts(gpa, &env.module_env.types, env.module_env.getIdentStore(), null); defer writer.deinit(); - const result = try writer.writeGet(rec_var); + const result = try writer.writeGet(rec_var, .wrap); // Should display as "List(...)" - the cycle is detected and shown as "..." try std.testing.expectEqualStrings("List(...)", result); @@ -1956,7 +1956,7 @@ test "type_writer - nested recursion_var displays correctly" { var writer = try TypeWriter.initFromParts(gpa, &env.module_env.types, env.module_env.getIdentStore(), null); defer writer.deinit(); - const result = try writer.writeGet(outer_rec_var); + const result = try writer.writeGet(outer_rec_var, .wrap); // Should display as "List({})" - following through the RecursionVars try std.testing.expectEqualStrings("List({})", result); @@ -2031,7 +2031,7 @@ test "recursion_var - integration: deep recursion with RecursionVar prevents inf var writer = try TypeWriter.initFromParts(gpa, &env.module_env.types, env.module_env.getIdentStore(), null); defer writer.deinit(); - const display = try writer.writeGet(var1); + const display = try writer.writeGet(var1, .wrap); // Should display "..." indicating cycle detection try std.testing.expect(std.mem.indexOf(u8, display, "...") != null); diff --git a/src/check/test/where_clause_test.zig.bak b/src/check/test/where_clause_test.zig.bak deleted file mode 100644 index d13d581e89..0000000000 --- a/src/check/test/where_clause_test.zig.bak +++ /dev/null @@ -1,320 +0,0 @@ -//! Comprehensive tests for where clause type checking functionality. -//! -//! These tests cover: -//! - Basic where clause parsing and type inference -//! - Method constraints on type variables -//! - Multiple constraints -//! - Constraint satisfaction -//! - Error cases - -const std = @import("std"); -const TestEnv = @import("./TestEnv.zig"); - -const testing = std.testing; - -// Basic where clause tests - -test "where clause - basic method constraint infers correctly" { - // Module A defines a type with to_str method - const source_a = - \\A := [Val(Str)].{ - \\ to_str : A -> Str - \\ to_str = |A.Val(s)| s - \\} - ; - var test_env_a = try TestEnv.init("A", source_a); - defer test_env_a.deinit(); - - // Module B uses A and defines a helper with where clause - const source_b = - \\import A - \\ - \\helper : a -> Str where [a.to_str : a -> Str] - \\helper = |x| x.to_str() - \\ - \\main : Str - \\main = helper(A.Val("hello")) - ; - var test_env_b = try TestEnv.initWithImport("B", source_b, "A", &test_env_a); - defer test_env_b.deinit(); - try test_env_b.assertDefType( - "helper", - "a -> Str where [a.to_str : a -> Str ]", - ); - try test_env_b.assertDefType("main", "Str"); -} - -test "where clause - polymorphic return type" { - const source_a = - \\A := [Val(Str)].{ - \\ to_str : A -> Str - \\ to_str = |A.Val(s)| s - \\} - ; - var test_env_a = try TestEnv.init("A", source_a); - defer test_env_a.deinit(); - - const source_b = - \\import A - \\ - \\helper : a -> b where [a.to_str : a -> b] - \\helper = |x| x.to_str() - \\ - \\main : Str - \\main = helper(A.Val("hello")) - ; - var test_env_b = try TestEnv.initWithImport("B", source_b, "A", &test_env_a); - defer test_env_b.deinit(); - try test_env_b.assertDefType( - "helper", - "a -> b where [a.to_str : a -> b ]", - ); - try test_env_b.assertDefType("main", "Str"); -} - -test "where clause - constraint with multiple args" { - const source_a = - \\A := [Box(Str)].{ - \\ transform : A, (Str -> Str) -> A - \\ transform = |A.Box(s), fn| A.Box(fn(s)) - \\} - ; - var test_env_a = try TestEnv.init("A", source_a); - defer test_env_a.deinit(); - - const source_b = - \\import A - \\ - \\modify : a, (Str -> Str) -> a where [a.transform : a, (Str -> Str) -> a] - \\modify = |x, fn| x.transform(fn) - \\ - \\main : A - \\main = modify(A.Box("hello"), |s| s) - ; - var test_env_b = try TestEnv.initWithImport("B", source_b, "A", &test_env_a); - defer test_env_b.deinit(); - try test_env_b.assertDefType( - "modify", - "a, (Str -> Str) -> a where [a.transform : a, (Str -> Str) -> a ]", - ); - try test_env_b.assertDefType("main", "A"); -} - -// Multiple constraints tests - -test "where clause - multiple constraints on same variable" { - const source_a = - \\A := [D(Str, U64)].{ - \\ to_str : A -> Str - \\ to_str = |A.D(s, _)| s - \\ - \\ to_u64 : A -> U64 - \\ to_u64 = |A.D(_, n)| n - \\} - ; - var test_env_a = try TestEnv.init("A", source_a); - defer test_env_a.deinit(); - - const source_b = - \\import A - \\ - \\both : a -> (Str, U64) where [a.to_str : a -> Str, a.to_u64 : a -> U64] - \\both = |x| (x.to_str(), x.to_u64()) - \\ - \\main : (Str, U64) - \\main = both(A.D("hello", 42)) - ; - var test_env_b = try TestEnv.initWithImport("B", source_b, "A", &test_env_a); - defer test_env_b.deinit(); - try test_env_b.assertDefType( - "both", - "a -> (Str, U64) where [a.to_str : a -> Str, a.to_u64 : a -> U64 ]", - ); - try test_env_b.assertDefType("main", "(Str, U64)"); -} - -// Cross-module where clause tests - -test "where clause - cross-module constraint satisfaction" { - const source_a = - \\A := [A(Str)].{ - \\ to_str : A -> Str - \\ to_str = |A.A(val)| val - \\} - ; - var test_env_a = try TestEnv.init("A", source_a); - defer test_env_a.deinit(); - try test_env_a.assertDefType("A.to_str", "A -> Str"); - - const source_b = - \\import A - \\ - \\helper : a -> Str where [a.to_str : a -> Str] - \\helper = |x| x.to_str() - \\ - \\main : Str - \\main = helper(A.A("hello")) - ; - var test_env_b = try TestEnv.initWithImport("B", source_b, "A", &test_env_a); - defer test_env_b.deinit(); - try test_env_b.assertDefType( - "helper", - "a -> Str where [a.to_str : a -> Str ]", - ); - try test_env_b.assertDefType("main", "Str"); -} - -test "where clause - cross-module polymorphic constraint" { - const source_a = - \\A := [A(Str)].{ - \\ to_str = |A.A(val)| val - \\ to_str2 = |x| x.to_str() - \\} - ; - var test_env_a = try TestEnv.init("A", source_a); - defer test_env_a.deinit(); - try test_env_a.assertDefType("A.to_str", "A -> Str"); - try test_env_a.assertDefType( - "A.to_str2", - "a -> b where [a.to_str : a -> b ]", - ); - - const source_b = - \\import A - \\ - \\main : Str - \\main = (A.A("hello")).to_str2() - ; - var test_env_b = try TestEnv.initWithImport("B", source_b, "A", &test_env_a); - defer test_env_b.deinit(); - try test_env_b.assertDefType("main", "Str"); -} - -// Nested/chained where clause tests - -test "where clause - chained method calls" { - const source_a = - \\A := [Box(Str)].{ - \\ get_value : A -> Str - \\ get_value = |A.Box(s)| s - \\ - \\ transform : A, (Str -> Str) -> A - \\ transform = |A.Box(s), fn| A.Box(fn(s)) - \\} - ; - var test_env_a = try TestEnv.init("A", source_a); - defer test_env_a.deinit(); - - const source_b = - \\import A - \\ - \\chain : a, (Str -> Str) -> Str where [a.transform : a, (Str -> Str) -> a, a.get_value : a -> Str] - \\chain = |x, fn| x.transform(fn).get_value() - \\ - \\main : Str - \\main = chain(A.Box("hello"), |s| s) - ; - var test_env_b = try TestEnv.initWithImport("B", source_b, "A", &test_env_a); - defer test_env_b.deinit(); - try test_env_b.assertDefType("main", "Str"); -} - -// Error case tests - -test "where clause - missing method on type" { - const source_a = - \\A := [Val(Str)].{} - ; - var test_env_a = try TestEnv.init("A", source_a); - defer test_env_a.deinit(); - - const source_b = - \\import A - \\ - \\helper : a -> Str where [a.to_str : a -> Str] - \\helper = |x| x.to_str() - \\ - \\main = helper(A.Val("hello")) - ; - var test_env_b = try TestEnv.initWithImport("B", source_b, "A", &test_env_a); - defer test_env_b.deinit(); - try test_env_b.assertFirstTypeError("MISSING METHOD"); -} - -test "where clause - method signature mismatch" { - const source_a = - \\A := [Val(Str)].{ - \\ to_str : A -> U64 - \\ to_str = |_| 42 - \\} - ; - var test_env_a = try TestEnv.init("A", source_a); - defer test_env_a.deinit(); - - const source_b = - \\import A - \\ - \\helper : a -> Str where [a.to_str : a -> Str] - \\helper = |x| x.to_str() - \\ - \\main = helper(A.Val("hello")) - ; - var test_env_b = try TestEnv.initWithImport("B", source_b, "A", &test_env_a); - defer test_env_b.deinit(); - try test_env_b.assertFirstTypeError("TYPE MISMATCH"); -} - -// Let polymorphism with where clauses - -test "where clause - same type used multiple times with where constraint" { - const source_a = - \\A := [A(Str)].{ - \\ to_str : A -> Str - \\ to_str = |A.A(s)| s - \\} - ; - var test_env_a = try TestEnv.init("A", source_a); - defer test_env_a.deinit(); - - const source_b = - \\import A - \\ - \\helper : a -> Str where [a.to_str : a -> Str] - \\helper = |x| x.to_str() - \\ - \\main : (Str, Str) - \\main = (helper(A.A("hello")), helper(A.A("world"))) - ; - var test_env_b = try TestEnv.initWithImport("B", source_b, "A", &test_env_a); - defer test_env_b.deinit(); - try test_env_b.assertDefType("main", "(Str, Str)"); -} - -// Where clause without annotation (inferred) - -test "where clause - inferred from method call without annotation" { - const source_a = - \\A := [Val(Str)].{ - \\ to_str : A -> Str - \\ to_str = |A.Val(s)| s - \\} - ; - var test_env_a = try TestEnv.init("A", source_a); - defer test_env_a.deinit(); - - const source_b = - \\import A - \\ - \\helper = |x| x.to_str() - \\ - \\main : Str - \\main = helper(A.Val("hello")) - ; - var test_env_b = try TestEnv.initWithImport("B", source_b, "A", &test_env_a); - defer test_env_b.deinit(); - try test_env_b.assertDefType( - "helper", - "a -> b where [a.to_str : a -> b ]", - ); - try test_env_b.assertDefType("main", "Str"); -} diff --git a/src/compile/test/type_printing_bug_test.zig b/src/compile/test/type_printing_bug_test.zig index 8d04c665c7..4bae845955 100644 --- a/src/compile/test/type_printing_bug_test.zig +++ b/src/compile/test/type_printing_bug_test.zig @@ -87,7 +87,7 @@ test "canonicalizeAndTypeCheckModule preserves Try types in type printing" { var type_writer = try env.initTypeWriter(); defer type_writer.deinit(); - try type_writer.write(map_result_var.?); + try type_writer.write(map_result_var.?, .wrap); const type_str = type_writer.get(); // Check that the type contains "Try" and not "Error" diff --git a/src/types/TypeWriter.zig b/src/types/TypeWriter.zig index 8320278168..339e93e52a 100644 --- a/src/types/TypeWriter.zig +++ b/src/types/TypeWriter.zig @@ -181,9 +181,18 @@ pub fn reset(self: *TypeWriter) void { self.name_counters = std.EnumMap(TypeContext, u32).init(.{}); } +fn hasSeenVar(self: *const TypeWriter, var_: Var) bool { + for (self.seen.items) |seen| { + if (seen == var_) return true; + } + return false; +} + +pub const Format = enum { one_line, wrap }; + /// Writes the current var into the the writers buffer and returns a bytes slice -pub fn writeGet(self: *TypeWriter, var_: Var) std.mem.Allocator.Error![]const u8 { - try self.write(var_); +pub fn writeGet(self: *TypeWriter, var_: Var, format: Format) std.mem.Allocator.Error![]const u8 { + try self.write(var_, format); return self.get(); } @@ -195,14 +204,14 @@ pub fn get(self: *const TypeWriter) []const u8 { /// Writes a type variable to the buffer, formatting it as a human-readable string. /// This clears any existing content in the buffer before writing. -pub fn write(self: *TypeWriter, var_: Var) std.mem.Allocator.Error!void { +pub fn write(self: *TypeWriter, var_: Var, format: Format) std.mem.Allocator.Error!void { self.reset(); var writer = self.buf.writer(); try self.writeVar(&writer, var_, var_); if (self.static_dispatch_constraints.items.len > 0) { - try self.writeWhereClause(&writer, var_); + try self.writeWhereClause(&writer, var_, format); } } @@ -211,7 +220,7 @@ pub fn write(self: *TypeWriter, var_: Var) std.mem.Allocator.Error!void { /// 1. All on same line: "where [a.plus : a -> a, b.minus : b -> b]" /// 2. All on next line: "\n where [a.plus : a -> a, b.minus : b -> b]" /// 3. One per line: "\n where [\n a.plus : a -> a,\n b.minus : b -> b,\n ]" -fn writeWhereClause(self: *TypeWriter, writer: *ByteWrite, root_var: Var) std.mem.Allocator.Error!void { +fn writeWhereClause(self: *TypeWriter, writer: *ByteWrite, root_var: Var, format: Format) std.mem.Allocator.Error!void { const var_len = self.buf.items.len; var tmp_writer = self.buf_tmp.writer(); @@ -287,7 +296,7 @@ fn writeWhereClause(self: *TypeWriter, writer: *ByteWrite, root_var: Var) std.me const line_len_if_all_on_next_line = 8 + constraints_len_if_on_same_line; // " where " = 8 chars // Choose formatting style based on line length - if (line_len_if_all_on_same_line <= 80) { + if (line_len_if_all_on_same_line <= 80 or format == .one_line) { // All constraints fit on the same line as the type // Example: MyType where [plus : a, a -> a, minus : a, a -> a] _ = try writer.write(" where ["); @@ -322,116 +331,6 @@ fn writeWhereClause(self: *TypeWriter, writer: *ByteWrite, root_var: Var) std.me } } -fn generateNextName(self: *TypeWriter, writer: *ByteWrite) !void { - // Generate name: a, b, ..., z, aa, ab, ..., az, ba, ... - // Skip any names that already exist in the identifier store - // We need at most one more name than the number of existing identifiers - const max_attempts = self.idents.interner.entry_count + 1; - var attempts: usize = 0; - while (attempts < max_attempts) : (attempts += 1) { - var n = self.next_name_index; - self.next_name_index += 1; - - var name_buf: [8]u8 = undefined; - var name_len: usize = 0; - - // Generate name in base-26: a, b, ..., z, aa, ab, ..., az, ba, ... - while (name_len < name_buf.len) { - name_buf[name_len] = @intCast('a' + (n % 26)); - name_len += 1; - n = n / 26; - if (n == 0) break; - n -= 1; - } - - // Names are generated in reverse order, so reverse the buffer - std.mem.reverse(u8, name_buf[0..name_len]); - - // Check if this name already exists in the identifier store - const candidate_name = name_buf[0..name_len]; - const exists = self.idents.interner.contains(candidate_name); - - if (!exists) { - // This name is available, use it - _ = try writer.write(candidate_name); - break; - } - // Name already exists, try the next one - } - - // This should never happen in practice, but let's handle it gracefully - if (attempts >= max_attempts) { - _ = try writer.write("var"); - try writer.print("{}", .{self.next_name_index}); - } -} - -fn generateContextualName(self: *TypeWriter, writer: *ByteWrite, context: TypeContext) std.mem.Allocator.Error!void { - const base_name = switch (context) { - .NumContent => "size", - .ListContent => "elem", - .RecordExtension => "others", - .TagUnionExtension => "others", - .RecordFieldContent => "field", - .TupleFieldContent => "field", - .FunctionArgument => "arg", - .FunctionReturn => "ret", - .General => { - // Fall back to generic name generation - try self.generateNextName(writer); - return; - }, - }; - - // Try to generate a name with increasing counters until we find one that doesn't collide - var counter = self.name_counters.get(context) orelse 0; - var found = false; - - // We need at most as many attempts as there are existing identifiers - const max_attempts = self.idents.interner.entry_count; - var attempts: usize = 0; - while (!found and attempts < max_attempts) : (attempts += 1) { - var buf: [32]u8 = undefined; - const candidate_name = if (counter == 0) - base_name - else blk: { - const name = std.fmt.bufPrint(&buf, "{s}{}", .{ base_name, counter + 1 }) catch { - // Buffer too small, fall back to generic name - try self.generateNextName(writer); - return; - }; - break :blk name; - }; - - // Check if this name already exists in the identifier store - const exists = self.idents.interner.contains(candidate_name); - - if (!exists) { - // This name is available, write it to the buffer - _ = try writer.write(candidate_name); - found = true; - } else { - // Try next counter - counter += 1; - } - } - - // If we couldn't find a unique contextual name, fall back to generic names - if (!found) { - try self.generateNextName(writer); - return; - } - - self.name_counters.put(context, counter + 1); -} - -fn hasSeenVar(self: *const TypeWriter, var_: Var) bool { - for (self.seen.items) |seen| { - if (seen == var_) return true; - } - return false; -} - /// Convert a var to a type string fn writeVarWithContext(self: *TypeWriter, writer: *ByteWrite, var_: Var, context: TypeContext, root_var: Var) std.mem.Allocator.Error!void { if (@intFromEnum(var_) >= self.types.slots.backing.len()) { @@ -1091,3 +990,106 @@ fn getDisplayName(self: *const TypeWriter, idx: Ident.Idx) []const u8 { return name; } + +fn generateContextualName(self: *TypeWriter, writer: *ByteWrite, context: TypeContext) std.mem.Allocator.Error!void { + const base_name = switch (context) { + .NumContent => "size", + .ListContent => "elem", + .RecordExtension => "others", + .TagUnionExtension => "others", + .RecordFieldContent => "field", + .TupleFieldContent => "field", + .FunctionArgument => "arg", + .FunctionReturn => "ret", + .General => { + // Fall back to generic name generation + try self.generateNextName(writer); + return; + }, + }; + + // Try to generate a name with increasing counters until we find one that doesn't collide + var counter = self.name_counters.get(context) orelse 0; + var found = false; + + // We need at most as many attempts as there are existing identifiers + const max_attempts = self.idents.interner.entry_count; + var attempts: usize = 0; + while (!found and attempts < max_attempts) : (attempts += 1) { + var buf: [32]u8 = undefined; + const candidate_name = if (counter == 0) + base_name + else blk: { + const name = std.fmt.bufPrint(&buf, "{s}{}", .{ base_name, counter + 1 }) catch { + // Buffer too small, fall back to generic name + try self.generateNextName(writer); + return; + }; + break :blk name; + }; + + // Check if this name already exists in the identifier store + const exists = self.idents.interner.contains(candidate_name); + + if (!exists) { + // This name is available, write it to the buffer + _ = try writer.write(candidate_name); + found = true; + } else { + // Try next counter + counter += 1; + } + } + + // If we couldn't find a unique contextual name, fall back to generic names + if (!found) { + try self.generateNextName(writer); + return; + } + + self.name_counters.put(context, counter + 1); +} + +fn generateNextName(self: *TypeWriter, writer: *ByteWrite) !void { + // Generate name: a, b, ..., z, aa, ab, ..., az, ba, ... + // Skip any names that already exist in the identifier store + // We need at most one more name than the number of existing identifiers + const max_attempts = self.idents.interner.entry_count + 1; + var attempts: usize = 0; + while (attempts < max_attempts) : (attempts += 1) { + var n = self.next_name_index; + self.next_name_index += 1; + + var name_buf: [8]u8 = undefined; + var name_len: usize = 0; + + // Generate name in base-26: a, b, ..., z, aa, ab, ..., az, ba, ... + while (name_len < name_buf.len) { + name_buf[name_len] = @intCast('a' + (n % 26)); + name_len += 1; + n = n / 26; + if (n == 0) break; + n -= 1; + } + + // Names are generated in reverse order, so reverse the buffer + std.mem.reverse(u8, name_buf[0..name_len]); + + // Check if this name already exists in the identifier store + const candidate_name = name_buf[0..name_len]; + const exists = self.idents.interner.contains(candidate_name); + + if (!exists) { + // This name is available, use it + _ = try writer.write(candidate_name); + break; + } + // Name already exists, try the next one + } + + // This should never happen in practice, but let's handle it gracefully + if (attempts >= max_attempts) { + _ = try writer.write("var"); + try writer.print("{}", .{self.next_name_index}); + } +} diff --git a/test/snapshots/annotations.md b/test/snapshots/annotations.md index ae028edde3..2a223a74c9 100644 --- a/test/snapshots/annotations.md +++ b/test/snapshots/annotations.md @@ -44,10 +44,12 @@ failPairDiffTypes = mkPair("1", 2) ^^^^^^^^^^^^^^ It has the type: - _Pair(Str)_ + + Pair(Str) But the type annotation says it should have the type: - _Pair(U8)_ + + Pair(U8) **MISSING METHOD** This **from_numeral** method is being called on a value whose type doesn't have that method: @@ -59,7 +61,7 @@ failPairDiffTypes = mkPair("1", 2) The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. @@ -72,10 +74,12 @@ failPairDiffTypes2 = Pair.Pair(1, "str") ^^^^^^^^^^^^^^^^^^^ It has the type: - _Pair(Str)_ + + Pair(Str) But the type annotation says it should have the type: - _Pair(U64)_ + + Pair(U64) **MISSING METHOD** This **from_numeral** method is being called on a value whose type doesn't have that method: @@ -87,7 +91,7 @@ failPairDiffTypes2 = Pair.Pair(1, "str") The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. @@ -100,10 +104,12 @@ mkPairInvalid = |x, y| Pair.Pair(x, y) ^^^^^^^^^^^^^^^ The tag is: - _Pair a b_ + + Pair a b But the nominal type needs it to be: - _Pair a a_ + + Pair a a # TOKENS ~~~zig diff --git a/test/snapshots/arrow_qualified_functions.md b/test/snapshots/arrow_qualified_functions.md index 5846fd978a..99eaad6c8d 100644 --- a/test/snapshots/arrow_qualified_functions.md +++ b/test/snapshots/arrow_qualified_functions.md @@ -173,10 +173,8 @@ test7 = 42->Ok (patt (type "b -> b")) (patt (type "b where [b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]")) (patt (type "b where [b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]")) - (patt (type "[Ok(b), .._others] - where [b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]")) - (patt (type "[Ok(b), .._others] - where [b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]"))) + (patt (type "[Ok(b), .._others] where [b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]")) + (patt (type "[Ok(b), .._others] where [b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]"))) (expressions (expr (type "Bool")) (expr (type "Bool")) @@ -184,8 +182,6 @@ test7 = 42->Ok (expr (type "b -> b")) (expr (type "b where [b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]")) (expr (type "b where [b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]")) - (expr (type "[Ok(b), .._others] - where [b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]")) - (expr (type "[Ok(b), .._others] - where [b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]")))) + (expr (type "[Ok(b), .._others] where [b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]")) + (expr (type "[Ok(b), .._others] where [b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]")))) ~~~ diff --git a/test/snapshots/binop_omnibus__single__no_spaces.md b/test/snapshots/binop_omnibus__single__no_spaces.md index afc15fab9a..1ff260865c 100644 --- a/test/snapshots/binop_omnibus__single__no_spaces.md +++ b/test/snapshots/binop_omnibus__single__no_spaces.md @@ -45,7 +45,7 @@ Err(foo)??12>5*5 or 13+2<5 and 10-1>=16 or 12<=3/5 The value's type, which does not have a method named **from_numeral**, is: - _Bool_ + Bool **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. diff --git a/test/snapshots/binops.md b/test/snapshots/binops.md index f4cf3c3ac2..08c3181063 100644 --- a/test/snapshots/binops.md +++ b/test/snapshots/binops.md @@ -186,13 +186,5 @@ EndOfFile, ~~~ # TYPES ~~~clojure -(expr (type "(a, b, c, d, e, Bool, Bool, Bool, Bool, _field, _field2, f, Bool, Bool, Error) - where [ - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)]), - d.from_numeral : Numeral -> Try(d, [InvalidNumeral(Str)]), - e.from_numeral : Numeral -> Try(e, [InvalidNumeral(Str)]), - f.from_numeral : Numeral -> Try(f, [InvalidNumeral(Str)]), - ]")) +(expr (type "(a, b, c, d, e, Bool, Bool, Bool, Bool, _field, _field2, f, Bool, Bool, Error) where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)]), d.from_numeral : Numeral -> Try(d, [InvalidNumeral(Str)]), e.from_numeral : Numeral -> Try(e, [InvalidNumeral(Str)]), f.from_numeral : Numeral -> Try(f, [InvalidNumeral(Str)])]")) ~~~ diff --git a/test/snapshots/can_closure_captures.md b/test/snapshots/can_closure_captures.md index 7d5c3b15a5..e71b29b2ba 100644 --- a/test/snapshots/can_closure_captures.md +++ b/test/snapshots/can_closure_captures.md @@ -256,17 +256,10 @@ main = (captureSimple, captureMultiple, outerFn, useClosure) (patt (type "a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) (patt (type "_arg -> a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) (patt (type "a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (patt (type "_arg -> (_arg2 -> a) - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (patt (type "_arg -> (_arg2 -> a) where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) (patt (type "a -> (_arg -> a)")) (patt (type "_arg -> a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (patt (type "(_arg -> a, _arg2 -> b, _arg3 -> (_arg4 -> c), _arg5 -> d) - where [ - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)]), - d.from_numeral : Numeral -> Try(d, [InvalidNumeral(Str)]), - ]"))) + (patt (type "(_arg -> a, _arg2 -> b, _arg3 -> (_arg4 -> c), _arg5 -> d) where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)]), d.from_numeral : Numeral -> Try(d, [InvalidNumeral(Str)])]"))) (expressions (expr (type "a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) (expr (type "_arg -> a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) @@ -274,15 +267,8 @@ main = (captureSimple, captureMultiple, outerFn, useClosure) (expr (type "a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) (expr (type "_arg -> a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) (expr (type "a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (expr (type "_arg -> (_arg2 -> a) - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (expr (type "_arg -> (_arg2 -> a) where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) (expr (type "a -> (_arg -> a)")) (expr (type "_arg -> a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (expr (type "(_arg -> a, _arg2 -> b, _arg3 -> (_arg4 -> c), _arg5 -> d) - where [ - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)]), - d.from_numeral : Numeral -> Try(d, [InvalidNumeral(Str)]), - ]")))) + (expr (type "(_arg -> a, _arg2 -> b, _arg3 -> (_arg4 -> c), _arg5 -> d) where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)]), d.from_numeral : Numeral -> Try(d, [InvalidNumeral(Str)])]")))) ~~~ diff --git a/test/snapshots/can_list_first_concrete.md b/test/snapshots/can_list_first_concrete.md index 15e5717d1f..d2f43bc89c 100644 --- a/test/snapshots/can_list_first_concrete.md +++ b/test/snapshots/can_list_first_concrete.md @@ -21,7 +21,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. @@ -35,7 +35,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. diff --git a/test/snapshots/can_list_heterogeneous.md b/test/snapshots/can_list_heterogeneous.md index 3bd2b920ac..e646793c34 100644 --- a/test/snapshots/can_list_heterogeneous.md +++ b/test/snapshots/can_list_heterogeneous.md @@ -21,7 +21,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. @@ -35,7 +35,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. diff --git a/test/snapshots/can_list_mismatch_then_nested_error.md b/test/snapshots/can_list_mismatch_then_nested_error.md index 91114347e9..0168ca9f5f 100644 --- a/test/snapshots/can_list_mismatch_then_nested_error.md +++ b/test/snapshots/can_list_mismatch_then_nested_error.md @@ -21,10 +21,12 @@ The second and third elements in this list have incompatible types: ^^^^^^^ ^^^^^^^^^^^^ The second element has this type: - _Str_ + + Str However, the third element has this type: - _List(Str)_ + + List(Str) All elements in a list must have compatible types. @@ -41,7 +43,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. @@ -55,7 +57,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. diff --git a/test/snapshots/can_list_multiline_mismatch.md b/test/snapshots/can_list_multiline_mismatch.md index 91f551191d..683056020b 100644 --- a/test/snapshots/can_list_multiline_mismatch.md +++ b/test/snapshots/can_list_multiline_mismatch.md @@ -25,7 +25,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. @@ -39,7 +39,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. diff --git a/test/snapshots/can_list_nested_heterogeneous.md b/test/snapshots/can_list_nested_heterogeneous.md index 1a4ad429c6..1c1b826f15 100644 --- a/test/snapshots/can_list_nested_heterogeneous.md +++ b/test/snapshots/can_list_nested_heterogeneous.md @@ -20,7 +20,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. diff --git a/test/snapshots/can_list_triple_nested_heterogeneous.md b/test/snapshots/can_list_triple_nested_heterogeneous.md index bcbbcd8051..b1026cf246 100644 --- a/test/snapshots/can_list_triple_nested_heterogeneous.md +++ b/test/snapshots/can_list_triple_nested_heterogeneous.md @@ -20,7 +20,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. diff --git a/test/snapshots/can_list_two_elements.md b/test/snapshots/can_list_two_elements.md index cf6dc2e8cb..b3f6e064b7 100644 --- a/test/snapshots/can_list_two_elements.md +++ b/test/snapshots/can_list_two_elements.md @@ -20,7 +20,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. diff --git a/test/snapshots/can_nested_heterogeneous_lists.md b/test/snapshots/can_nested_heterogeneous_lists.md index 4271c7409f..90474ad535 100644 --- a/test/snapshots/can_nested_heterogeneous_lists.md +++ b/test/snapshots/can_nested_heterogeneous_lists.md @@ -21,7 +21,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. @@ -35,7 +35,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. diff --git a/test/snapshots/comprehensive/Container.md b/test/snapshots/comprehensive/Container.md index aeff8f8ddb..28475d9cbf 100644 --- a/test/snapshots/comprehensive/Container.md +++ b/test/snapshots/comprehensive/Container.md @@ -1227,14 +1227,7 @@ main = { (patt (type "(a -> a), a -> a")) (patt (type "(a -> b) -> ((b -> c) -> (a -> c))")) (patt (type "a, c -> d where [a.map : a, (b -> c) -> d]")) - (patt (type "{ chained: a, final: a, id_results: (e, Str, [True, .._others]), processed: c, transformed: a } - where [ - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)]), - e.from_numeral : Numeral -> Try(e, [InvalidNumeral(Str)]), - ]"))) + (patt (type "{ chained: a, final: a, id_results: (e, Str, [True, .._others]), processed: c, transformed: a } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)]), e.from_numeral : Numeral -> Try(e, [InvalidNumeral(Str)])]"))) (type_decls (nominal (type "Container(a)") (ty-header (name "Container") @@ -1248,12 +1241,5 @@ main = { (expr (type "(a -> a), a -> a")) (expr (type "(a -> b) -> ((b -> c) -> (a -> c))")) (expr (type "a, c -> d where [a.map : a, (b -> c) -> d]")) - (expr (type "{ chained: a, final: a, id_results: (e, Str, [True, .._others]), processed: c, transformed: a } - where [ - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)]), - e.from_numeral : Numeral -> Try(e, [InvalidNumeral(Str)]), - ]")))) + (expr (type "{ chained: a, final: a, id_results: (e, Str, [True, .._others]), processed: c, transformed: a } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)]), e.from_numeral : Numeral -> Try(e, [InvalidNumeral(Str)])]")))) ~~~ diff --git a/test/snapshots/eval/call_float_literal.md b/test/snapshots/eval/call_float_literal.md index d50a5cf658..9e2a9ef0dd 100644 --- a/test/snapshots/eval/call_float_literal.md +++ b/test/snapshots/eval/call_float_literal.md @@ -20,8 +20,7 @@ x = 12.34() The value's type, which does not have a method named **from_numeral**, is: - _({}) -> _ret_ - + ({}) -> _ret # TOKENS ~~~zig diff --git a/test/snapshots/eval/tuple_numbers.md b/test/snapshots/eval/tuple_numbers.md index 307bc67666..1fff1a63bd 100644 --- a/test/snapshots/eval/tuple_numbers.md +++ b/test/snapshots/eval/tuple_numbers.md @@ -85,21 +85,5 @@ NO CHANGE ~~~ # TYPES ~~~clojure -(expr (type "(U8, I8, U16, I16, U32, I32, U64, I64, U128, I128, F32, F64, Dec, a, b, c, d, e, f, g, h, i, j, k, l, m, n) - where [ - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)]), - d.from_numeral : Numeral -> Try(d, [InvalidNumeral(Str)]), - e.from_numeral : Numeral -> Try(e, [InvalidNumeral(Str)]), - f.from_numeral : Numeral -> Try(f, [InvalidNumeral(Str)]), - g.from_numeral : Numeral -> Try(g, [InvalidNumeral(Str)]), - h.from_numeral : Numeral -> Try(h, [InvalidNumeral(Str)]), - i.from_numeral : Numeral -> Try(i, [InvalidNumeral(Str)]), - j.from_numeral : Numeral -> Try(j, [InvalidNumeral(Str)]), - k.from_numeral : Numeral -> Try(k, [InvalidNumeral(Str)]), - l.from_numeral : Numeral -> Try(l, [InvalidNumeral(Str)]), - m.from_numeral : Numeral -> Try(m, [InvalidNumeral(Str)]), - n.from_numeral : Numeral -> Try(n, [InvalidNumeral(Str)]), - ]")) +(expr (type "(U8, I8, U16, I16, U32, I32, U64, I64, U128, I128, F32, F64, Dec, a, b, c, d, e, f, g, h, i, j, k, l, m, n) where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)]), d.from_numeral : Numeral -> Try(d, [InvalidNumeral(Str)]), e.from_numeral : Numeral -> Try(e, [InvalidNumeral(Str)]), f.from_numeral : Numeral -> Try(f, [InvalidNumeral(Str)]), g.from_numeral : Numeral -> Try(g, [InvalidNumeral(Str)]), h.from_numeral : Numeral -> Try(h, [InvalidNumeral(Str)]), i.from_numeral : Numeral -> Try(i, [InvalidNumeral(Str)]), j.from_numeral : Numeral -> Try(j, [InvalidNumeral(Str)]), k.from_numeral : Numeral -> Try(k, [InvalidNumeral(Str)]), l.from_numeral : Numeral -> Try(l, [InvalidNumeral(Str)]), m.from_numeral : Numeral -> Try(m, [InvalidNumeral(Str)]), n.from_numeral : Numeral -> Try(n, [InvalidNumeral(Str)])]")) ~~~ diff --git a/test/snapshots/expr/ann_effectful_fn.md b/test/snapshots/expr/ann_effectful_fn.md index 80d60fe720..e921c2d9e8 100644 --- a/test/snapshots/expr/ann_effectful_fn.md +++ b/test/snapshots/expr/ann_effectful_fn.md @@ -44,7 +44,8 @@ This expression produces a value, but it's not being used: ^^^^ It has the type: - _[Bool, .._others]_ + + [Bool, .._others] **UNUSED VALUE** This expression produces a value, but it's not being used: @@ -55,7 +56,8 @@ This expression produces a value, but it's not being used: ^^^^^^^^^^^^^ It has the type: - _[LaunchNukeErr, .._others]_ + + [LaunchNukeErr, .._others] # TOKENS ~~~zig diff --git a/test/snapshots/expr/list_type_err.md b/test/snapshots/expr/list_type_err.md index a3de718ba2..a1840f7629 100644 --- a/test/snapshots/expr/list_type_err.md +++ b/test/snapshots/expr/list_type_err.md @@ -20,7 +20,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. diff --git a/test/snapshots/expr/not_tag.md b/test/snapshots/expr/not_tag.md index 825364313d..a72f7c91c3 100644 --- a/test/snapshots/expr/not_tag.md +++ b/test/snapshots/expr/not_tag.md @@ -19,11 +19,13 @@ This expression is used in an unexpected way: ^^^^ It has the type: - _[C(a), ..[False, True, .._others]] - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]_ + + [C(a), ..[False, True, .._others]] + where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])] But I expected it to be: - _Bool_ + + Bool # TOKENS ~~~zig diff --git a/test/snapshots/expr/record_literal_field_bang.md b/test/snapshots/expr/record_literal_field_bang.md index 413620e864..84f49aa6bf 100644 --- a/test/snapshots/expr/record_literal_field_bang.md +++ b/test/snapshots/expr/record_literal_field_bang.md @@ -55,6 +55,5 @@ EndOfFile, ~~~ # TYPES ~~~clojure -(expr (type "{ answer: a, launchTheNukes!: {} -> _ret } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) +(expr (type "{ answer: a, launchTheNukes!: {} -> _ret } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) ~~~ diff --git a/test/snapshots/expr/record_simple.md b/test/snapshots/expr/record_simple.md index a392574d86..4bf58c6228 100644 --- a/test/snapshots/expr/record_simple.md +++ b/test/snapshots/expr/record_simple.md @@ -41,6 +41,5 @@ NO CHANGE ~~~ # TYPES ~~~clojure -(expr (type "{ age: a, name: Str } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) +(expr (type "{ age: a, name: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) ~~~ diff --git a/test/snapshots/expr/record_updater_basic.md b/test/snapshots/expr/record_updater_basic.md index 3f0603eeb1..9111b170f9 100644 --- a/test/snapshots/expr/record_updater_basic.md +++ b/test/snapshots/expr/record_updater_basic.md @@ -69,13 +69,9 @@ NO CHANGE ~~~clojure (inferred-types (defs - (patt (type "{ age: a, name: Str } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (patt (type "{ age: a, name: Str } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]"))) + (patt (type "{ age: a, name: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (patt (type "{ age: a, name: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]"))) (expressions - (expr (type "{ age: a, name: Str } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (expr (type "{ age: a, name: Str } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")))) + (expr (type "{ age: a, name: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (expr (type "{ age: a, name: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")))) ~~~ diff --git a/test/snapshots/expr/record_updater_chained.md b/test/snapshots/expr/record_updater_chained.md index e2ef5bfdf5..cbbcdc6873 100644 --- a/test/snapshots/expr/record_updater_chained.md +++ b/test/snapshots/expr/record_updater_chained.md @@ -119,21 +119,13 @@ NO CHANGE ~~~clojure (inferred-types (defs - (patt (type "{ age: a, city: Str, name: Str } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (patt (type "{ age: a, city: Str, name: Str } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (patt (type "{ age: a, city: Str, name: Str } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (patt (type "{ age: a, city: Str, name: Str } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]"))) + (patt (type "{ age: a, city: Str, name: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (patt (type "{ age: a, city: Str, name: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (patt (type "{ age: a, city: Str, name: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (patt (type "{ age: a, city: Str, name: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]"))) (expressions - (expr (type "{ age: a, city: Str, name: Str } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (expr (type "{ age: a, city: Str, name: Str } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (expr (type "{ age: a, city: Str, name: Str } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (expr (type "{ age: a, city: Str, name: Str } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")))) + (expr (type "{ age: a, city: Str, name: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (expr (type "{ age: a, city: Str, name: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (expr (type "{ age: a, city: Str, name: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (expr (type "{ age: a, city: Str, name: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")))) ~~~ diff --git a/test/snapshots/expr/tag_applications_simple.md b/test/snapshots/expr/tag_applications_simple.md index cb996a9c7b..32d41b8a33 100644 --- a/test/snapshots/expr/tag_applications_simple.md +++ b/test/snapshots/expr/tag_applications_simple.md @@ -31,9 +31,8 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _[Ok([Just(a), .._others]), .._others2] - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]_ - + [Ok([Just(a), .._others]), .._others2] + where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])] # TOKENS ~~~zig @@ -149,11 +148,5 @@ EndOfFile, ~~~ # TYPES ~~~clojure -(expr (type "List([Err(Str), Just(a), Left(b), None, Nothing, Ok(Str), Right(c), Some([Ok([Just(d), .._others]), .._others2]), Try([Ok([Some([True, .._others3]), .._others4]), .._others5]), .._others6]) - where [ - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)]), - d.from_numeral : Numeral -> Try(d, [InvalidNumeral(Str)]), - ]")) +(expr (type "List([Err(Str), Just(a), Left(b), None, Nothing, Ok(Str), Right(c), Some([Ok([Just(d), .._others]), .._others2]), Try([Ok([Some([True, .._others3]), .._others4]), .._others5]), .._others6]) where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)]), d.from_numeral : Numeral -> Try(d, [InvalidNumeral(Str)])]")) ~~~ diff --git a/test/snapshots/expr/tag_vs_function_calls.md b/test/snapshots/expr/tag_vs_function_calls.md index 69d3a90b56..12af7a2f25 100644 --- a/test/snapshots/expr/tag_vs_function_calls.md +++ b/test/snapshots/expr/tag_vs_function_calls.md @@ -164,11 +164,5 @@ EndOfFile, ~~~ # TYPES ~~~clojure -(expr (type "{ addOne: a -> a, errTag: [Err(Str), .._others], nested: [Some([Ok([Just(b), .._others2]), .._others3]), .._others4], noneTag: [None, .._others5], okTag: [Ok(Str), .._others6], result: Error, someTag: [Some(c), .._others7], tagList: List([Some(d), ..[None, .._others8]]) } - where [ - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)]), - d.from_numeral : Numeral -> Try(d, [InvalidNumeral(Str)]), - ]")) +(expr (type "{ addOne: a -> a, errTag: [Err(Str), .._others], nested: [Some([Ok([Just(b), .._others2]), .._others3]), .._others4], noneTag: [None, .._others5], okTag: [Ok(Str), .._others6], result: Error, someTag: [Some(c), .._others7], tagList: List([Some(d), ..[None, .._others8]]) } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)]), d.from_numeral : Numeral -> Try(d, [InvalidNumeral(Str)])]")) ~~~ diff --git a/test/snapshots/expr/tag_with_payload.md b/test/snapshots/expr/tag_with_payload.md index b00a632dcf..e7b6bb1fa9 100644 --- a/test/snapshots/expr/tag_with_payload.md +++ b/test/snapshots/expr/tag_with_payload.md @@ -34,6 +34,5 @@ NO CHANGE ~~~ # TYPES ~~~clojure -(expr (type "[Some(a), .._others] - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) +(expr (type "[Some(a), .._others] where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) ~~~ diff --git a/test/snapshots/expr/tuple.md b/test/snapshots/expr/tuple.md index eed44d5a6d..db7b6d970d 100644 --- a/test/snapshots/expr/tuple.md +++ b/test/snapshots/expr/tuple.md @@ -39,6 +39,5 @@ NO CHANGE ~~~ # TYPES ~~~clojure -(expr (type "(a, Str, [True, .._others]) - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) +(expr (type "(a, Str, [True, .._others]) where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) ~~~ diff --git a/test/snapshots/expr/tuple_simple_unbound.md b/test/snapshots/expr/tuple_simple_unbound.md index 6ab96b69bb..0aa26c346b 100644 --- a/test/snapshots/expr/tuple_simple_unbound.md +++ b/test/snapshots/expr/tuple_simple_unbound.md @@ -39,6 +39,5 @@ NO CHANGE ~~~ # TYPES ~~~clojure -(expr (type "(a, Str, [True, .._others]) - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) +(expr (type "(a, Str, [True, .._others]) where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) ~~~ diff --git a/test/snapshots/expr/tuple_type.md b/test/snapshots/expr/tuple_type.md index 6529a7959e..f47df5608a 100644 --- a/test/snapshots/expr/tuple_type.md +++ b/test/snapshots/expr/tuple_type.md @@ -26,7 +26,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. @@ -40,7 +40,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. diff --git a/test/snapshots/expr/two_arg_closure.md b/test/snapshots/expr/two_arg_closure.md index 21ddfc74f1..88b7c182fc 100644 --- a/test/snapshots/expr/two_arg_closure.md +++ b/test/snapshots/expr/two_arg_closure.md @@ -38,6 +38,5 @@ NO CHANGE ~~~ # TYPES ~~~clojure -(expr (type "_arg, _arg2 -> a - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) +(expr (type "_arg, _arg2 -> a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) ~~~ diff --git a/test/snapshots/expr_if_missing_else.md b/test/snapshots/expr_if_missing_else.md index be8a7eec6b..de1c38cf40 100644 --- a/test/snapshots/expr_if_missing_else.md +++ b/test/snapshots/expr_if_missing_else.md @@ -32,8 +32,7 @@ foo = if tru 0 The value's type, which does not have a method named **from_numeral**, is: - _{}_ - + {} # TOKENS ~~~zig diff --git a/test/snapshots/formatting/multiline/everything.md b/test/snapshots/formatting/multiline/everything.md index b61d14c361..a0bf7b85bb 100644 --- a/test/snapshots/formatting/multiline/everything.md +++ b/test/snapshots/formatting/multiline/everything.md @@ -321,7 +321,6 @@ The where clause syntax _A_ is not supported: This syntax was used for abilities, which have been removed from Roc. Use method constraints like `where [a.methodName(args) -> ret]` instead. - **UNSUPPORTED WHERE CLAUSE** The where clause syntax _B_ is not supported: **everything.md:61:3:61:6:** @@ -332,7 +331,6 @@ The where clause syntax _B_ is not supported: This syntax was used for abilities, which have been removed from Roc. Use method constraints like `where [a.methodName(args) -> ret]` instead. - # TOKENS ~~~zig KwImport,UpperIdent,KwExposing,OpenSquare, diff --git a/test/snapshots/formatting/singleline/everything.md b/test/snapshots/formatting/singleline/everything.md index d340027a07..8b10156ac4 100644 --- a/test/snapshots/formatting/singleline/everything.md +++ b/test/snapshots/formatting/singleline/everything.md @@ -215,7 +215,6 @@ g : e -> e where [e.A, e.B] This syntax was used for abilities, which have been removed from Roc. Use method constraints like `where [a.methodName(args) -> ret]` instead. - **UNSUPPORTED WHERE CLAUSE** The where clause syntax _B_ is not supported: **everything.md:15:24:15:27:** @@ -226,7 +225,6 @@ g : e -> e where [e.A, e.B] This syntax was used for abilities, which have been removed from Roc. Use method constraints like `where [a.methodName(args) -> ret]` instead. - # TOKENS ~~~zig KwImport,UpperIdent,KwExposing,OpenSquare,UpperIdent,Comma,UpperIdent,CloseSquare, diff --git a/test/snapshots/formatting/singleline_with_comma/everything.md b/test/snapshots/formatting/singleline_with_comma/everything.md index 3a90577a13..a952be4e3e 100644 --- a/test/snapshots/formatting/singleline_with_comma/everything.md +++ b/test/snapshots/formatting/singleline_with_comma/everything.md @@ -214,7 +214,6 @@ g : e -> e where [e.A, e.B,] This syntax was used for abilities, which have been removed from Roc. Use method constraints like `where [a.methodName(args) -> ret]` instead. - **UNSUPPORTED WHERE CLAUSE** The where clause syntax _B_ is not supported: **everything.md:14:24:14:27:** @@ -225,7 +224,6 @@ g : e -> e where [e.A, e.B,] This syntax was used for abilities, which have been removed from Roc. Use method constraints like `where [a.methodName(args) -> ret]` instead. - # TOKENS ~~~zig KwImport,UpperIdent,KwExposing,OpenSquare,UpperIdent,Comma,UpperIdent,Comma,CloseSquare, diff --git a/test/snapshots/fuzz_crash/fuzz_crash_019.md b/test/snapshots/fuzz_crash/fuzz_crash_019.md index 2a2670aee2..c12b2aba0d 100644 --- a/test/snapshots/fuzz_crash/fuzz_crash_019.md +++ b/test/snapshots/fuzz_crash/fuzz_crash_019.md @@ -878,7 +878,6 @@ The type _List_ expects 1 argument, but got 0 instead. ``` - **UNUSED VALUE** This expression produces a value, but it's not being used: **fuzz_crash_019.md:39:2:39:3:** @@ -888,7 +887,8 @@ This expression produces a value, but it's not being used: ^ It has the type: - _f where [f.from_numeral : Numeral -> Try(f, [InvalidNumeral(Str)])]_ + + f where [f.from_numeral : Numeral -> Try(f, [InvalidNumeral(Str)])] **INCOMPATIBLE MATCH PATTERNS** The pattern in the fourth branch of this `match` differs from previous ones: @@ -916,15 +916,15 @@ The pattern in the fourth branch of this `match` differs from previous ones: ^^^^^ The fourth pattern has this type: - _Str_ + + Str But all the previous patterns have this type: - _[Blue, .._others]_ + + [Blue, .._others] All patterns in an `match` must have compatible types. - - **UNUSED VALUE** This expression produces a value, but it's not being used: **fuzz_crash_019.md:1:1:1:1:** @@ -934,7 +934,8 @@ This expression produces a value, but it's not being used: ^ It has the type: - __f_ + + _f **TOO FEW ARGUMENTS** The function `me` expects 2 arguments, but 1 was provided: @@ -946,7 +947,8 @@ The function `me` expects 2 arguments, but 1 was provided: ``` The function has the signature: - _[Blue, .._others], [Tb, .._others2] -> Error_ + + [Blue, .._others], [Tb, .._others2] -> Error **UNUSED VALUE** This expression produces a value, but it's not being used: @@ -957,7 +959,8 @@ This expression produces a value, but it's not being used: ^^^^^^ It has the type: - _Str_ + + Str **MISSING METHOD** This **from_numeral** method is being called on a value whose type doesn't have that method: @@ -969,7 +972,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. @@ -987,11 +990,12 @@ This expression produces a value, but it's not being used: ``` It has the type: - _(f, Str, Error, [O, .._others], (Error, Error), List(j)) - where [ - f.from_numeral : Numeral -> Try(f, [InvalidNumeral(Str)]), - j.from_numeral : Numeral -> Try(j, [InvalidNumeral(Str)]), - ]_ + + (f, Str, Error, [O, .._others], (Error, Error), List(j)) + where [ + f.from_numeral : Numeral -> Try(f, [InvalidNumeral(Str)]), + j.from_numeral : Numeral -> Try(j, [InvalidNumeral(Str)]), + ] **UNUSED VALUE** This expression produces a value, but it's not being used: @@ -1002,7 +1006,8 @@ This expression produces a value, but it's not being used: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ It has the type: - _Bool_ + + Bool **UNUSED VALUE** This expression produces a value, but it's not being used: @@ -1013,7 +1018,8 @@ This expression produces a value, but it's not being used: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ It has the type: - __f_ + + _f **UNUSED VALUE** This expression produces a value, but it's not being used: @@ -1024,7 +1030,8 @@ This expression produces a value, but it's not being used: ^^^^^^^^ It has the type: - __f_ + + _f # TOKENS ~~~zig diff --git a/test/snapshots/fuzz_crash/fuzz_crash_020.md b/test/snapshots/fuzz_crash/fuzz_crash_020.md index dc4be1d144..ef133ff978 100644 --- a/test/snapshots/fuzz_crash/fuzz_crash_020.md +++ b/test/snapshots/fuzz_crash/fuzz_crash_020.md @@ -889,7 +889,6 @@ The type _List_ expects 1 argument, but got 0 instead. ``` - **UNUSED VALUE** This expression produces a value, but it's not being used: **fuzz_crash_020.md:39:2:39:3:** @@ -899,7 +898,8 @@ This expression produces a value, but it's not being used: ^ It has the type: - _f where [f.from_numeral : Numeral -> Try(f, [InvalidNumeral(Str)])]_ + + f where [f.from_numeral : Numeral -> Try(f, [InvalidNumeral(Str)])] **INCOMPATIBLE MATCH PATTERNS** The pattern in the fourth branch of this `match` differs from previous ones: @@ -927,15 +927,15 @@ The pattern in the fourth branch of this `match` differs from previous ones: ^^^^^ The fourth pattern has this type: - _Str_ + + Str But all the previous patterns have this type: - _[Blue, .._others]_ + + [Blue, .._others] All patterns in an `match` must have compatible types. - - **UNUSED VALUE** This expression produces a value, but it's not being used: **fuzz_crash_020.md:1:1:1:1:** @@ -945,7 +945,8 @@ This expression produces a value, but it's not being used: ^ It has the type: - __f_ + + _f **UNUSED VALUE** This expression produces a value, but it's not being used: @@ -956,7 +957,8 @@ This expression produces a value, but it's not being used: ^^^^^^ It has the type: - _Str_ + + Str **MISSING METHOD** This **from_numeral** method is being called on a value whose type doesn't have that method: @@ -968,7 +970,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. @@ -986,11 +988,12 @@ This expression produces a value, but it's not being used: ``` It has the type: - _(f, Str, Error, [O, .._others], (Error, Error), List(j)) - where [ - f.from_numeral : Numeral -> Try(f, [InvalidNumeral(Str)]), - j.from_numeral : Numeral -> Try(j, [InvalidNumeral(Str)]), - ]_ + + (f, Str, Error, [O, .._others], (Error, Error), List(j)) + where [ + f.from_numeral : Numeral -> Try(f, [InvalidNumeral(Str)]), + j.from_numeral : Numeral -> Try(j, [InvalidNumeral(Str)]), + ] **UNUSED VALUE** This expression produces a value, but it's not being used: @@ -1001,7 +1004,8 @@ This expression produces a value, but it's not being used: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ It has the type: - _Bool_ + + Bool **UNUSED VALUE** This expression produces a value, but it's not being used: @@ -1012,7 +1016,8 @@ This expression produces a value, but it's not being used: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ It has the type: - __f_ + + _f **UNUSED VALUE** This expression produces a value, but it's not being used: @@ -1023,7 +1028,8 @@ This expression produces a value, but it's not being used: ^^^^^^^^ It has the type: - __f_ + + _f # TOKENS ~~~zig diff --git a/test/snapshots/fuzz_crash/fuzz_crash_023.md b/test/snapshots/fuzz_crash/fuzz_crash_023.md index baf66a0615..d7f7183c4b 100644 --- a/test/snapshots/fuzz_crash/fuzz_crash_023.md +++ b/test/snapshots/fuzz_crash/fuzz_crash_023.md @@ -953,7 +953,8 @@ This `if` condition needs to be a _Bool_: ^^^ Right now, it has the type: - _U64_ + + U64 Every `if` condition must evaluate to a _Bool_–either `True` or `False`. @@ -1020,15 +1021,15 @@ The pattern in the fourth branch of this `match` differs from previous ones: ^^^^^ The fourth pattern has this type: - _Str_ + + Str But all the previous patterns have this type: - _[Red, ..[Blue, Green, .._others2]]_ + + [Red, ..[Blue, Green, .._others2]] All patterns in an `match` must have compatible types. - - **UNUSED VALUE** This expression produces a value, but it's not being used: **fuzz_crash_023.md:1:1:1:1:** @@ -1038,7 +1039,8 @@ This expression produces a value, but it's not being used: ^ It has the type: - __d_ + + _d **TOO FEW ARGUMENTS** The function `match_time` expects 2 arguments, but 1 was provided: @@ -1050,7 +1052,8 @@ The function `match_time` expects 2 arguments, but 1 was provided: ``` The function has the signature: - _[Red, ..[Blue, Green, .._others2]], _arg -> Error_ + + [Red, ..[Blue, Green, .._others2]], _arg -> Error **TYPE MISMATCH** This expression is used in an unexpected way: @@ -1061,10 +1064,12 @@ This expression is used in an unexpected way: ^ It has the type: - _U64_ + + U64 But I expected it to be: - _Str_ + + Str **UNUSED VALUE** This expression produces a value, but it's not being used: @@ -1075,7 +1080,8 @@ This expression produces a value, but it's not being used: ^^^ It has the type: - _[Blue, .._others2]_ + + [Blue, .._others2] **UNUSED VALUE** This expression produces a value, but it's not being used: @@ -1086,7 +1092,8 @@ This expression produces a value, but it's not being used: ^^^^^^^^^^^^^^^^^^^^^^^^^^^ It has the type: - __d_ + + _d **TYPE MISMATCH** This expression is used in an unexpected way: @@ -1148,10 +1155,12 @@ main! = |_| { # Yeah I can leave a comment here ``` It has the type: - _List(Error) => Error_ + + List(Error) => Error But the type annotation says it should have the type: - _List(Error) -> Error_ + + List(Error) -> Error # TOKENS ~~~zig diff --git a/test/snapshots/fuzz_crash/fuzz_crash_027.md b/test/snapshots/fuzz_crash/fuzz_crash_027.md index 1139527d7e..fe51165cd4 100644 --- a/test/snapshots/fuzz_crash/fuzz_crash_027.md +++ b/test/snapshots/fuzz_crash/fuzz_crash_027.md @@ -894,7 +894,6 @@ The type _List_ expects 1 argument, but got 0 instead. ``` - **INVALID IF CONDITION** This `if` condition needs to be a _Bool_: **fuzz_crash_027.md:50:5:** @@ -904,7 +903,8 @@ This `if` condition needs to be a _Bool_: ^^^ Right now, it has the type: - _U64_ + + U64 Every `if` condition must evaluate to a _Bool_–either `True` or `False`. @@ -947,15 +947,15 @@ ist ^^^^^ The third pattern has this type: - _Str_ + + Str But all the previous patterns have this type: - _[Red, Blue, .._others2]_ + + [Red, Blue, .._others2] All patterns in an `match` must have compatible types. - - **UNUSED VALUE** This expression produces a value, but it's not being used: **fuzz_crash_027.md:1:1:1:1:** @@ -965,7 +965,8 @@ This expression produces a value, but it's not being used: ^ It has the type: - __d_ + + _d **TOO FEW ARGUMENTS** The function `match_time` expects 2 arguments, but 1 was provided: @@ -977,7 +978,8 @@ The function `match_time` expects 2 arguments, but 1 was provided: ``` The function has the signature: - _[Blue, Red, .._others2], _arg -> Error_ + + [Blue, Red, .._others2], _arg -> Error **MISSING METHOD** This **from_numeral** method is being called on a value whose type doesn't have that method: @@ -989,7 +991,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. @@ -1003,7 +1005,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. @@ -1017,7 +1019,7 @@ The value before this **+** operator has a type that doesn't have a **plus** met The value's type, which does not have a method named **plus**, is: - _Str_ + Str **Hint:**The **+** operator calls a method named **plus** on the value preceding it, passing the value after the operator as the one argument. @@ -1033,10 +1035,12 @@ This expression is used in an unexpected way: ``` It has the type: - _[Stdoline!(Error), ..[Err(_d), Ok({ }), .._others2]]_ + + [Stdoline!(Error), ..[Err(_d), Ok({ }), .._others2]] But the type annotation says it should have the type: - _Try({ }, _d)_ + + Try({ }, _d) **TYPE MISMATCH** This expression is used in an unexpected way: @@ -1094,10 +1098,12 @@ e[, # afarg ``` It has the type: - _List(Error) => Error_ + + List(Error) => Error But the type annotation says it should have the type: - _List(Error) -> Error_ + + List(Error) -> Error # TOKENS ~~~zig diff --git a/test/snapshots/fuzz_crash/fuzz_crash_028.md b/test/snapshots/fuzz_crash/fuzz_crash_028.md index 22311bee3dfa209366373798056a948ac7e0da7d..b610f877a3858733b63cdb909862eab7d41a8418 100644 GIT binary patch delta 130 zcmZp@$o%^P^M>02o9_f9GjVV!06}m`(PWQcLsl?n(qpm7Q-iH0UkqL>3Kod=DlOJg z(9?_0FUd$PDvq6eJ~(;udL4zyyrF{ZU={Hxlhr~GK(tSO9jZE6Fzh%)rn+|WgD?Y# OEum&6n02n{NfAFmWmXL40sYQT$}LU_%)&FFGhSMMuFYr!-YZK~FC}za%5I zs5mx$@}yv^$)|#sia`{4l@_B)p9)T%yk19PGJB{X2UtmbO8jK`&;$Gs^$_!bMo)Sy g%@{wKGwe7-RdsFr Try(a, [InvalidNumeral(Str)])]")) - (patt (type "{ age: a, name: Str } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]"))) + (patt (type "{ age: a, name: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (patt (type "{ age: a, name: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]"))) (expressions - (expr (type "{ age: a, name: Str } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (expr (type "{ age: a, name: Str } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")))) + (expr (type "{ age: a, name: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (expr (type "{ age: a, name: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")))) ~~~ diff --git a/test/snapshots/fuzz_crash/fuzz_crash_049.md b/test/snapshots/fuzz_crash/fuzz_crash_049.md index a13a3875ff342d35bad5f5035aa2bc7311b52527..604e867fad26fa597c86361cf92bd469a6754cc2 100644 GIT binary patch delta 167 zcmaF3i@kprd&3sSU#=Wn3P2EQW-^`Gjqw3Hm=~Y2{k0pTP0w`A%ZyW|FS^O-$fz^j z@eZTa^sLK_uG4$3FnS@0T2F7d!)QHyKSe`X$aKNGi~#_16F^P? delta 305 zcmeC*#r|*?d&3sSU#^@AKoB2lW)eT0$&K*=2bde562JYW8>3AR6PLpDb+;HDr`z6O zG`)A zy$Gmg1*uk;?s%2a8e&A@9jFo8w_RmSVL^6-$n^YML|PwxivsJxZi=1$;5wuD^uu=; FeE?S-T%G^` diff --git a/test/snapshots/if_then_else/if_then_else_9.md b/test/snapshots/if_then_else/if_then_else_9.md index 6116dc04d9..2ce951c031 100644 --- a/test/snapshots/if_then_else/if_then_else_9.md +++ b/test/snapshots/if_then_else/if_then_else_9.md @@ -40,7 +40,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Bool_ + Bool **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. @@ -54,8 +54,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _[A, .._others]_ - + [A, .._others] **MISSING METHOD** This **from_numeral** method is being called on a value whose type doesn't have that method: @@ -67,8 +66,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _[A, .._others]_ - + [A, .._others] # TOKENS ~~~zig diff --git a/test/snapshots/if_then_else/if_then_else_nested_chain.md b/test/snapshots/if_then_else/if_then_else_nested_chain.md index e3751750c9..10d7a36919 100644 --- a/test/snapshots/if_then_else/if_then_else_nested_chain.md +++ b/test/snapshots/if_then_else/if_then_else_nested_chain.md @@ -125,15 +125,7 @@ NO CHANGE ~~~clojure (inferred-types (defs - (patt (type "a -> Str - where [ - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - a.is_eq : a, a -> Bool, - ]"))) + (patt (type "a -> Str where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), a.is_eq : a, a -> Bool]"))) (expressions - (expr (type "a -> Str - where [ - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - a.is_eq : a, a -> Bool, - ]")))) + (expr (type "a -> Str where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), a.is_eq : a, a -> Bool]")))) ~~~ diff --git a/test/snapshots/if_then_else/if_then_else_simple_block_formatting.md b/test/snapshots/if_then_else/if_then_else_simple_block_formatting.md index 760dfea000..5e6a199c8a 100644 --- a/test/snapshots/if_then_else/if_then_else_simple_block_formatting.md +++ b/test/snapshots/if_then_else/if_then_else_simple_block_formatting.md @@ -34,8 +34,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _[A, .._others]_ - + [A, .._others] # TOKENS ~~~zig diff --git a/test/snapshots/if_then_else/if_then_else_simple_file.md b/test/snapshots/if_then_else/if_then_else_simple_file.md index 073265cd52..1e549ccc6e 100644 --- a/test/snapshots/if_then_else/if_then_else_simple_file.md +++ b/test/snapshots/if_then_else/if_then_else_simple_file.md @@ -28,10 +28,12 @@ foo = if 1 A ^^^^^^^ The `else` branch has the type: - _Str_ + + Str But the `then` branch has the type: - _[A, .._others]_ + + [A, .._others] All branches in an `if` must have compatible types. @@ -48,7 +50,7 @@ foo = if 1 A The value's type, which does not have a method named **from_numeral**, is: - _Bool_ + Bool **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. diff --git a/test/snapshots/if_then_else/if_then_else_simple_tag.md b/test/snapshots/if_then_else/if_then_else_simple_tag.md index 84684660ac..29b0bf9adf 100644 --- a/test/snapshots/if_then_else/if_then_else_simple_tag.md +++ b/test/snapshots/if_then_else/if_then_else_simple_tag.md @@ -49,9 +49,5 @@ NO CHANGE ~~~ # TYPES ~~~clojure -(expr (type "[Ok(a), Err(b), .._others] - where [ - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - ]")) +(expr (type "[Ok(a), Err(b), .._others] where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]")) ~~~ diff --git a/test/snapshots/issue/simple_underscore_error.md b/test/snapshots/issue/simple_underscore_error.md index 15f7837f95..809bfed586 100644 --- a/test/snapshots/issue/simple_underscore_error.md +++ b/test/snapshots/issue/simple_underscore_error.md @@ -35,7 +35,7 @@ foo = 42 The value's type, which does not have a method named **from_numeral**, is: - _BadType_ + BadType **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. diff --git a/test/snapshots/issue/test_error_propagation.md b/test/snapshots/issue/test_error_propagation.md index 027dac3f3e..b7f66fe00c 100644 --- a/test/snapshots/issue/test_error_propagation.md +++ b/test/snapshots/issue/test_error_propagation.md @@ -36,10 +36,12 @@ value = "test" ^^^^^^ It has the type: - _Str_ + + Str But the type annotation says it should have the type: - _GoodAlias_ + + GoodAlias # TOKENS ~~~zig diff --git a/test/snapshots/issue/underscore_error_propagation.md b/test/snapshots/issue/underscore_error_propagation.md index b3a2a1be59..5886e63221 100644 --- a/test/snapshots/issue/underscore_error_propagation.md +++ b/test/snapshots/issue/underscore_error_propagation.md @@ -44,10 +44,12 @@ value = "test" ^^^^^^ It has the type: - _Str_ + + Str But the type annotation says it should have the type: - _BadDerived_ + + BadDerived **TYPE MISMATCH** This expression is used in an unexpected way: @@ -58,10 +60,12 @@ goodValue = "test" ^^^^^^ It has the type: - _Str_ + + Str But the type annotation says it should have the type: - _GoodDerived_ + + GoodDerived # TOKENS ~~~zig diff --git a/test/snapshots/issue/underscore_error_type.md b/test/snapshots/issue/underscore_error_type.md index 832a3f5fe4..8c4874444e 100644 --- a/test/snapshots/issue/underscore_error_type.md +++ b/test/snapshots/issue/underscore_error_type.md @@ -131,7 +131,7 @@ foo = 42 The value's type, which does not have a method named **from_numeral**, is: - _BadType_ + BadType **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. @@ -144,10 +144,12 @@ bar = [1, 2, 3] ^^^^^^^^^ It has the type: - _List(a) where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]_ + + List(a) where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])] But the type annotation says it should have the type: - _BadList_ + + BadList **TYPE MISMATCH** This expression is used in an unexpected way: @@ -158,11 +160,13 @@ baz = { field: "hi", other: 5 } ^^^^^^^^^^^^^^^^^^^^^^^^^ It has the type: - _{ field: Str, other: a } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]_ + + { field: Str, other: a } + where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])] But the type annotation says it should have the type: - _BadRecord_ + + BadRecord **TYPE MISMATCH** This expression is used in an unexpected way: @@ -173,10 +177,12 @@ qux = |x| x ^^^^^ It has the type: - _a -> a_ + + a -> a But the type annotation says it should have the type: - _BadFunction_ + + BadFunction **TYPE MISMATCH** This expression is used in an unexpected way: @@ -187,10 +193,12 @@ quux = ("hello", 42) ^^^^^^^^^^^^^ It has the type: - _(Str, a) where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]_ + + (Str, a) where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])] But the type annotation says it should have the type: - _BadTuple_ + + BadTuple # TOKENS ~~~zig diff --git a/test/snapshots/issue/usage_test.md b/test/snapshots/issue/usage_test.md index 912ae4fb44..52cf8c5411 100644 --- a/test/snapshots/issue/usage_test.md +++ b/test/snapshots/issue/usage_test.md @@ -49,7 +49,7 @@ value = 42 The value's type, which does not have a method named **from_numeral**, is: - _UsedType_ + UsedType **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. diff --git a/test/snapshots/lambda_annotation_mismatch_error.md b/test/snapshots/lambda_annotation_mismatch_error.md index 34cdd62156..99d121cbab 100644 --- a/test/snapshots/lambda_annotation_mismatch_error.md +++ b/test/snapshots/lambda_annotation_mismatch_error.md @@ -28,7 +28,7 @@ string_function = |x| x + 42 The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. @@ -42,7 +42,7 @@ string_function = |x| x + 42 The value's type, which does not have a method named **plus**, is: - _Str_ + Str **Hint:**The **+** operator calls a method named **plus** on the value preceding it, passing the value after the operator as the one argument. diff --git a/test/snapshots/lambda_multi_arg_mismatch.md b/test/snapshots/lambda_multi_arg_mismatch.md index 9a4ada1415..36345e0e09 100644 --- a/test/snapshots/lambda_multi_arg_mismatch.md +++ b/test/snapshots/lambda_multi_arg_mismatch.md @@ -83,10 +83,12 @@ The first and seventh arguments to `multi_arg_fn` must have compatible types, bu ^^^^ The first argument has the type: - _Str_ + + Str But the seventh argument has the type: - _[True, .._others]_ + + [True, .._others] `multi_arg_fn` needs these arguments to have compatible types. @@ -100,7 +102,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. @@ -114,7 +116,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. diff --git a/test/snapshots/let_polymorphism_complex.md b/test/snapshots/let_polymorphism_complex.md index 8c127e5729..cc5f4b7ca8 100644 --- a/test/snapshots/let_polymorphism_complex.md +++ b/test/snapshots/let_polymorphism_complex.md @@ -1066,52 +1066,22 @@ main = |_| { (patt (type "List([True, False, .._others])")) (patt (type "List(List(_a))")) (patt (type "List(List(a)) where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (patt (type "{ count: a, items: List(_b) } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (patt (type "{ count: a, items: List(b) } - where [ - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - ]")) - (patt (type "{ count: a, items: List(Str) } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (patt (type "{ data: List(_a), metadata: { description: Str, ratio: b, version: c } } - where [ - b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)]), - ]")) - (patt (type "{ data: List(a), metadata: { description: Str, ratio: b, version: c }, name: Str } - where [ - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)]), - ]")) - (patt (type "{ data: List(Str), metadata: { description: Str, ratio: a, version: b }, name: Str } - where [ - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - ]")) + (patt (type "{ count: a, items: List(_b) } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (patt (type "{ count: a, items: List(b) } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]")) + (patt (type "{ count: a, items: List(Str) } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (patt (type "{ data: List(_a), metadata: { description: Str, ratio: b, version: c } } where [b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)])]")) + (patt (type "{ data: List(a), metadata: { description: Str, ratio: b, version: c }, name: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)])]")) + (patt (type "{ data: List(Str), metadata: { description: Str, ratio: a, version: b }, name: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]")) (patt (type "a -> { value: a, wrapper: List(a) }")) - (patt (type "{ value: a, wrapper: List(a) } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (patt (type "{ value: a, wrapper: List(a) } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) (patt (type "{ value: Str, wrapper: List(Str) }")) - (patt (type "{ value: a, wrapper: List(a) } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (patt (type "{ level1: { collection: List(_a), level2: { items: List(b), level3: { data: List(_c), value: b } } }, results: List({ data: List(d), tag: Str }) } - where [ - b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - d.from_numeral : Numeral -> Try(d, [InvalidNumeral(Str)]), - ]")) + (patt (type "{ value: a, wrapper: List(a) } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (patt (type "{ level1: { collection: List(_a), level2: { items: List(b), level3: { data: List(_c), value: b } } }, results: List({ data: List(d), tag: Str }) } where [b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), d.from_numeral : Numeral -> Try(d, [InvalidNumeral(Str)])]")) (patt (type "a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) (patt (type "a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) (patt (type "List(a) where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (patt (type "{ base: a, derived: List(a) } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (patt (type "{ computations: { from_frac: a, from_num: b, list_from_num: List(b) }, empty_lists: { in_list: List(List(_c)), in_record: { data: List(_d) }, raw: List(_e) }, numbers: { float: a, list: List(b), value: b }, strings: { list: List(Str), value: Str } } - where [ - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - ]")) + (patt (type "{ base: a, derived: List(a) } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (patt (type "{ computations: { from_frac: a, from_num: b, list_from_num: List(b) }, empty_lists: { in_list: List(List(_c)), in_record: { data: List(_d) }, raw: List(_e) }, numbers: { float: a, list: List(b), value: b }, strings: { list: List(Str), value: Str } } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]")) (patt (type "_arg -> a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]"))) (expressions (expr (type "a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) @@ -1125,51 +1095,21 @@ main = |_| { (expr (type "List([True, False, .._others])")) (expr (type "List(List(_a))")) (expr (type "List(List(a)) where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (expr (type "{ count: a, items: List(_b) } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (expr (type "{ count: a, items: List(b) } - where [ - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - ]")) - (expr (type "{ count: a, items: List(Str) } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (expr (type "{ data: List(_a), metadata: { description: Str, ratio: b, version: c } } - where [ - b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)]), - ]")) - (expr (type "{ data: List(a), metadata: { description: Str, ratio: b, version: c }, name: Str } - where [ - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)]), - ]")) - (expr (type "{ data: List(Str), metadata: { description: Str, ratio: a, version: b }, name: Str } - where [ - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - ]")) + (expr (type "{ count: a, items: List(_b) } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (expr (type "{ count: a, items: List(b) } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]")) + (expr (type "{ count: a, items: List(Str) } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (expr (type "{ data: List(_a), metadata: { description: Str, ratio: b, version: c } } where [b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)])]")) + (expr (type "{ data: List(a), metadata: { description: Str, ratio: b, version: c }, name: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)])]")) + (expr (type "{ data: List(Str), metadata: { description: Str, ratio: a, version: b }, name: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]")) (expr (type "a -> { value: a, wrapper: List(a) }")) - (expr (type "{ value: a, wrapper: List(a) } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (expr (type "{ value: a, wrapper: List(a) } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) (expr (type "{ value: Str, wrapper: List(Str) }")) - (expr (type "{ value: a, wrapper: List(a) } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (expr (type "{ level1: { collection: List(_a), level2: { items: List(b), level3: { data: List(_c), value: b } } }, results: List({ data: List(d), tag: Str }) } - where [ - b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - d.from_numeral : Numeral -> Try(d, [InvalidNumeral(Str)]), - ]")) + (expr (type "{ value: a, wrapper: List(a) } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (expr (type "{ level1: { collection: List(_a), level2: { items: List(b), level3: { data: List(_c), value: b } } }, results: List({ data: List(d), tag: Str }) } where [b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), d.from_numeral : Numeral -> Try(d, [InvalidNumeral(Str)])]")) (expr (type "a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) (expr (type "a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) (expr (type "List(a) where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (expr (type "{ base: a, derived: List(a) } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (expr (type "{ computations: { from_frac: a, from_num: b, list_from_num: List(b) }, empty_lists: { in_list: List(List(_c)), in_record: { data: List(_d) }, raw: List(_e) }, numbers: { float: a, list: List(b), value: b }, strings: { list: List(Str), value: Str } } - where [ - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - ]")) + (expr (type "{ base: a, derived: List(a) } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (expr (type "{ computations: { from_frac: a, from_num: b, list_from_num: List(b) }, empty_lists: { in_list: List(List(_c)), in_record: { data: List(_d) }, raw: List(_e) }, numbers: { float: a, list: List(b), value: b }, strings: { list: List(Str), value: Str } } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]")) (expr (type "_arg -> a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")))) ~~~ diff --git a/test/snapshots/let_polymorphism_error.md b/test/snapshots/let_polymorphism_error.md index c60f3bb0c7..fddf034759 100644 --- a/test/snapshots/let_polymorphism_error.md +++ b/test/snapshots/let_polymorphism_error.md @@ -20,7 +20,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. diff --git a/test/snapshots/let_polymorphism_expr.md b/test/snapshots/let_polymorphism_expr.md index a68114606c..e27a87d2a6 100644 --- a/test/snapshots/let_polymorphism_expr.md +++ b/test/snapshots/let_polymorphism_expr.md @@ -85,6 +85,5 @@ match [] { ~~~ # TYPES ~~~clojure -(expr (type "{ empty: List(_a), ints: List(b), strs: List(Str) } - where [b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]")) +(expr (type "{ empty: List(_a), ints: List(b), strs: List(Str) } where [b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]")) ~~~ diff --git a/test/snapshots/let_polymorphism_records.md b/test/snapshots/let_polymorphism_records.md index 8c63393175..b556e1d9a0 100644 --- a/test/snapshots/let_polymorphism_records.md +++ b/test/snapshots/let_polymorphism_records.md @@ -63,7 +63,7 @@ updated_mismatch = update_data(str_container, 99) The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. @@ -76,7 +76,8 @@ This expression produces a value, but it's not being used: ^^^^^^^^^^^^^^^ It has the type: - _{ ..a, data: b }, b -> { ..a, data: b }_ + + { ..a, data: b }, b -> { ..a, data: b } **MISSING METHOD** This **from_numeral** method is being called on a value whose type doesn't have that method: @@ -88,8 +89,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _{ ..a, data: b }, b -> { ..a, data: b }_ - + { ..a, data: b }, b -> { ..a, data: b } # TOKENS ~~~zig @@ -418,32 +418,18 @@ NO CHANGE (patt (type "Str")) (patt (type "List(_a)")) (patt (type "List(a) where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (patt (type "a -> { count: b, data: a } - where [b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]")) - (patt (type "{ count: a, data: b } - where [ - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - ]")) - (patt (type "{ count: a, data: Str } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (patt (type "{ count: a, data: List(_b) } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (patt (type "a -> { count: b, data: a } where [b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]")) + (patt (type "{ count: a, data: b } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]")) + (patt (type "{ count: a, data: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (patt (type "{ count: a, data: List(_b) } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) (patt (type "{ ..a, data: b }, b -> { ..a, data: b }")) - (patt (type "{ count: a, data: b } - where [ - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - ]")) - (patt (type "{ count: a, data: Str } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (patt (type "{ count: a, data: Str } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (patt (type "{ count: a, data: b } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]")) + (patt (type "{ count: a, data: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (patt (type "{ count: a, data: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) (patt (type "a -> { value: a }")) (patt (type "{ value: a } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) (patt (type "{ value: Str }")) - (patt (type "{ value: List(a) } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (patt (type "{ value: List(a) } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) (patt (type "_arg -> a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]"))) (expressions (expr (type "a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) @@ -451,31 +437,17 @@ NO CHANGE (expr (type "Str")) (expr (type "List(_a)")) (expr (type "List(a) where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (expr (type "a -> { count: b, data: a } - where [b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]")) - (expr (type "{ count: a, data: b } - where [ - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - ]")) - (expr (type "{ count: a, data: Str } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (expr (type "{ count: a, data: List(_b) } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (expr (type "a -> { count: b, data: a } where [b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]")) + (expr (type "{ count: a, data: b } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]")) + (expr (type "{ count: a, data: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (expr (type "{ count: a, data: List(_b) } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) (expr (type "{ ..a, data: b }, b -> { ..a, data: b }")) - (expr (type "{ count: a, data: b } - where [ - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - ]")) - (expr (type "{ count: a, data: Str } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) - (expr (type "{ count: a, data: Str } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (expr (type "{ count: a, data: b } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]")) + (expr (type "{ count: a, data: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (expr (type "{ count: a, data: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) (expr (type "a -> { value: a }")) (expr (type "{ value: a } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) (expr (type "{ value: Str }")) - (expr (type "{ value: List(a) } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) + (expr (type "{ value: List(a) } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) (expr (type "_arg -> a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")))) ~~~ diff --git a/test/snapshots/match_expr/basic_tag_union.md b/test/snapshots/match_expr/basic_tag_union.md index 3d3abb4375..2a00a9fafd 100644 --- a/test/snapshots/match_expr/basic_tag_union.md +++ b/test/snapshots/match_expr/basic_tag_union.md @@ -36,7 +36,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. diff --git a/test/snapshots/match_expr/literal_patterns.md b/test/snapshots/match_expr/literal_patterns.md index 652570eb14..02c4e092dc 100644 --- a/test/snapshots/match_expr/literal_patterns.md +++ b/test/snapshots/match_expr/literal_patterns.md @@ -28,7 +28,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. @@ -42,7 +42,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. @@ -56,8 +56,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _[Answer, Zero, Greeting, .._others]_ - + [Answer, Zero, Greeting, .._others] **MISSING METHOD** This **from_numeral** method is being called on a value whose type doesn't have that method: @@ -69,7 +68,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. diff --git a/test/snapshots/match_expr/pattern_alternatives_mixed.md b/test/snapshots/match_expr/pattern_alternatives_mixed.md index 83c6178be9..b31aee8ad7 100644 --- a/test/snapshots/match_expr/pattern_alternatives_mixed.md +++ b/test/snapshots/match_expr/pattern_alternatives_mixed.md @@ -34,15 +34,15 @@ match ... { ^^^^^ The third pattern has this type: - _[Ok(_a), .._others]_ + + [Ok(_a), .._others] But all the previous patterns have this type: - _Str_ + + Str All patterns in an `match` must have compatible types. - - **MISSING METHOD** This **from_numeral** method is being called on a value whose type doesn't have that method: **pattern_alternatives_mixed.md:2:10:2:11:** @@ -53,7 +53,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. diff --git a/test/snapshots/match_expr/pattern_as_basic.md b/test/snapshots/match_expr/pattern_as_basic.md index 83eb9fed85..3bee813e3b 100644 --- a/test/snapshots/match_expr/pattern_as_basic.md +++ b/test/snapshots/match_expr/pattern_as_basic.md @@ -92,9 +92,5 @@ match (1, 2) { ~~~ # TYPES ~~~clojure -(expr (type "(a, b) - where [ - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - ]")) +(expr (type "(a, b) where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)])]")) ~~~ diff --git a/test/snapshots/match_expr/record_pattern_edge_cases.md b/test/snapshots/match_expr/record_pattern_edge_cases.md index fab5bf1c1e..26e128d846 100644 --- a/test/snapshots/match_expr/record_pattern_edge_cases.md +++ b/test/snapshots/match_expr/record_pattern_edge_cases.md @@ -27,10 +27,12 @@ This expression is used in an unexpected way: ^ It has the type: - _{ c: Str }_ + + { c: Str } But I expected it to be: - _Str_ + + Str # TOKENS ~~~zig diff --git a/test/snapshots/multiline_string_complex.md b/test/snapshots/multiline_string_complex.md index f9e9b090a0..3a34a2b7b6 100644 --- a/test/snapshots/multiline_string_complex.md +++ b/test/snapshots/multiline_string_complex.md @@ -66,10 +66,12 @@ This expression is used in an unexpected way: ^^ It has the type: - _Str_ + + Str But I expected it to be: - _Bool_ + + Bool **MISSING METHOD** This **from_numeral** method is being called on a value whose type doesn't have that method: @@ -81,7 +83,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. diff --git a/test/snapshots/nominal/nominal_associated_in_tuples.md b/test/snapshots/nominal/nominal_associated_in_tuples.md index 47ca05bfc3..aaaac58a7c 100644 --- a/test/snapshots/nominal/nominal_associated_in_tuples.md +++ b/test/snapshots/nominal/nominal_associated_in_tuples.md @@ -58,7 +58,6 @@ boxed : Container(Foo.Bar) ^^^^^^^^^^^^^^^^^^ - # TOKENS ~~~zig UpperIdent,OpColonEqual,OpenSquare,UpperIdent,CloseSquare,Dot,OpenCurly, diff --git a/test/snapshots/nominal/nominal_tag_simple.md b/test/snapshots/nominal/nominal_tag_simple.md index ad1d058ab2..9b180dbaac 100644 --- a/test/snapshots/nominal/nominal_tag_simple.md +++ b/test/snapshots/nominal/nominal_tag_simple.md @@ -25,10 +25,12 @@ yellow = Color.Yellow ^^^^^^^^^^^^ The tag is: - _Yellow_ + + Yellow But the nominal type needs it to one of: - _[Blue, Green, Red]_ + + [Blue, Green, Red] # TOKENS ~~~zig diff --git a/test/snapshots/numbers.md b/test/snapshots/numbers.md index 39c7004a0f..bb6de73c01 100644 --- a/test/snapshots/numbers.md +++ b/test/snapshots/numbers.md @@ -105,18 +105,5 @@ EndOfFile, ~~~ # TYPES ~~~clojure -(expr (type "(a, b, c, d, e, f, g, h, i, j, k) - where [ - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)]), - d.from_numeral : Numeral -> Try(d, [InvalidNumeral(Str)]), - e.from_numeral : Numeral -> Try(e, [InvalidNumeral(Str)]), - f.from_numeral : Numeral -> Try(f, [InvalidNumeral(Str)]), - g.from_numeral : Numeral -> Try(g, [InvalidNumeral(Str)]), - h.from_numeral : Numeral -> Try(h, [InvalidNumeral(Str)]), - i.from_numeral : Numeral -> Try(i, [InvalidNumeral(Str)]), - j.from_numeral : Numeral -> Try(j, [InvalidNumeral(Str)]), - k.from_numeral : Numeral -> Try(k, [InvalidNumeral(Str)]), - ]")) +(expr (type "(a, b, c, d, e, f, g, h, i, j, k) where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)]), d.from_numeral : Numeral -> Try(d, [InvalidNumeral(Str)]), e.from_numeral : Numeral -> Try(e, [InvalidNumeral(Str)]), f.from_numeral : Numeral -> Try(f, [InvalidNumeral(Str)]), g.from_numeral : Numeral -> Try(g, [InvalidNumeral(Str)]), h.from_numeral : Numeral -> Try(h, [InvalidNumeral(Str)]), i.from_numeral : Numeral -> Try(i, [InvalidNumeral(Str)]), j.from_numeral : Numeral -> Try(j, [InvalidNumeral(Str)]), k.from_numeral : Numeral -> Try(k, [InvalidNumeral(Str)])]")) ~~~ diff --git a/test/snapshots/numeric_let_generalize_in_block.md b/test/snapshots/numeric_let_generalize_in_block.md index a363674093..27f2b2bbf9 100644 --- a/test/snapshots/numeric_let_generalize_in_block.md +++ b/test/snapshots/numeric_let_generalize_in_block.md @@ -24,10 +24,12 @@ The first argument being passed to this function has the wrong type: ^ This argument has the type: - _I64_ + + I64 But the function needs the first argument to be: - _Dec_ + + Dec # TOKENS ~~~zig diff --git a/test/snapshots/plume_package/Color.md b/test/snapshots/plume_package/Color.md index 309df3d382..1ef431d20e 100644 --- a/test/snapshots/plume_package/Color.md +++ b/test/snapshots/plume_package/Color.md @@ -223,7 +223,7 @@ This **to_frac** method is being called on a value whose type doesn't have that The value's type, which does not have a method named **to_frac**, is: - _U8_ + U8 **Hint:** For this to work, the type would need to have a method named **to_frac** associated with it in the type's declaration. @@ -237,7 +237,7 @@ This **is_char_in_hex_range** method is being called on a value whose type doesn The value's type, which does not have a method named **is_char_in_hex_range**, is: - _U8_ + U8 **Hint:** For this to work, the type would need to have a method named **is_char_in_hex_range** associated with it in the type's declaration. @@ -251,7 +251,7 @@ This **is_char_in_hex_range** method is being called on a value whose type doesn The value's type, which does not have a method named **is_char_in_hex_range**, is: - _U8_ + U8 **Hint:** For this to work, the type would need to have a method named **is_char_in_hex_range** associated with it in the type's declaration. @@ -265,7 +265,7 @@ This **is_char_in_hex_range** method is being called on a value whose type doesn The value's type, which does not have a method named **is_char_in_hex_range**, is: - _U8_ + U8 **Hint:** For this to work, the type would need to have a method named **is_char_in_hex_range** associated with it in the type's declaration. @@ -279,7 +279,7 @@ This **is_char_in_hex_range** method is being called on a value whose type doesn The value's type, which does not have a method named **is_char_in_hex_range**, is: - _U8_ + U8 **Hint:** For this to work, the type would need to have a method named **is_char_in_hex_range** associated with it in the type's declaration. @@ -293,7 +293,7 @@ This **is_char_in_hex_range** method is being called on a value whose type doesn The value's type, which does not have a method named **is_char_in_hex_range**, is: - _U8_ + U8 **Hint:** For this to work, the type would need to have a method named **is_char_in_hex_range** associated with it in the type's declaration. @@ -307,7 +307,7 @@ This **is_char_in_hex_range** method is being called on a value whose type doesn The value's type, which does not have a method named **is_char_in_hex_range**, is: - _U8_ + U8 **Hint:** For this to work, the type would need to have a method named **is_char_in_hex_range** associated with it in the type's declaration. @@ -321,7 +321,7 @@ This **is_named_color** method is being called on a value whose type doesn't hav The value's type, which does not have a method named **is_named_color**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **is_named_color** associated with it in the type's declaration. @@ -335,7 +335,7 @@ expect rgb(124, 56, 245).to_str() == "rgb(124, 56, 245)" The value's type, which does not have a method named **to_str**, is: - _Color_ + Color **Hint:** For this to work, the type would need to have a method named **to_str** associated with it in the type's declaration. @@ -349,7 +349,7 @@ expect rgba(124, 56, 245, 255).to_str() == "rgba(124, 56, 245, 1.0)" The value's type, which does not have a method named **to_str**, is: - _Color_ + Color **Hint:** For this to work, the type would need to have a method named **to_str** associated with it in the type's declaration. diff --git a/test/snapshots/records/error_duplicate_fields.md b/test/snapshots/records/error_duplicate_fields.md index ad7e42d89c..1467516e90 100644 --- a/test/snapshots/records/error_duplicate_fields.md +++ b/test/snapshots/records/error_duplicate_fields.md @@ -90,6 +90,5 @@ NO CHANGE ~~~ # TYPES ~~~clojure -(expr (type "{ age: a, email: Str, name: Str } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) +(expr (type "{ age: a, email: Str, name: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) ~~~ diff --git a/test/snapshots/records/function_record_parameter_capture.md b/test/snapshots/records/function_record_parameter_capture.md index 6d43bc8be3..9340d20f33 100644 --- a/test/snapshots/records/function_record_parameter_capture.md +++ b/test/snapshots/records/function_record_parameter_capture.md @@ -99,6 +99,5 @@ NO CHANGE ~~~ # TYPES ~~~clojure -(expr (type "{ a: b, age: c, name: Str } -> { full_record: { a: b, age: c, name: Str }, greeting: Str, is_adult: Bool } - where [c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)])]")) +(expr (type "{ a: b, age: c, name: Str } -> { full_record: { a: b, age: c, name: Str }, greeting: Str, is_adult: Bool } where [c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)])]")) ~~~ diff --git a/test/snapshots/records/polymorphism.md b/test/snapshots/records/polymorphism.md index 9ae6feab8c..3d2889a288 100644 --- a/test/snapshots/records/polymorphism.md +++ b/test/snapshots/records/polymorphism.md @@ -26,12 +26,11 @@ This **to_str** method is being called on a value whose type doesn't have that m The value's type, which does not have a method named **to_str**, is: - _{ pair1: { first: a, second: Str }, pair2: { first: Str, second: b }, pair3: { first: [True, .._others], second: [False, .._others2] } } - where [ - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - ]_ - + { pair1: { first: a, second: Str }, pair2: { first: Str, second: b }, pair3: { first: [True, .._others], second: [False, .._others2] } } + where [ + a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), + b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), + ] # TOKENS ~~~zig diff --git a/test/snapshots/records/record_different_fields_error.md b/test/snapshots/records/record_different_fields_error.md index eaac6fae53..17728b0ee9 100644 --- a/test/snapshots/records/record_different_fields_error.md +++ b/test/snapshots/records/record_different_fields_error.md @@ -556,7 +556,8 @@ This expression produces a value, but it's not being used: ^^^^^^^^^^ It has the type: - _[PascalCase, .._others]_ + + [PascalCase, .._others] **UNUSED VALUE** This expression produces a value, but it's not being used: @@ -567,7 +568,8 @@ This expression produces a value, but it's not being used: ^^^^^^^^ It has the type: - _Str_ + + Str **UNUSED VALUE** This expression produces a value, but it's not being used: @@ -578,7 +580,8 @@ This expression produces a value, but it's not being used: ^^^^^ It has the type: - __a_ + + _a **UNUSED VALUE** This expression produces a value, but it's not being used: @@ -589,7 +592,8 @@ This expression produces a value, but it's not being used: ^^^^^^^ It has the type: - _Str_ + + Str **UNUSED VALUE** This expression produces a value, but it's not being used: @@ -600,7 +604,8 @@ This expression produces a value, but it's not being used: ^^^^^^^^^^^ It has the type: - _Str_ + + Str # TOKENS ~~~zig diff --git a/test/snapshots/records/record_different_fields_reserved_error.md b/test/snapshots/records/record_different_fields_reserved_error.md index 9dd2d70089..5a3b002552 100644 --- a/test/snapshots/records/record_different_fields_reserved_error.md +++ b/test/snapshots/records/record_different_fields_reserved_error.md @@ -457,7 +457,8 @@ This expression produces a value, but it's not being used: ^^^^^^^^^^^^^^^^ It has the type: - _Str_ + + Str **UNUSED VALUE** This expression produces a value, but it's not being used: @@ -468,7 +469,8 @@ This expression produces a value, but it's not being used: ^^^^^^^^^^^^^ It has the type: - _Str_ + + Str # TOKENS ~~~zig diff --git a/test/snapshots/records/record_mixed_field_syntax.md b/test/snapshots/records/record_mixed_field_syntax.md index 16b7fd2d43..f2724c3f3c 100644 --- a/test/snapshots/records/record_mixed_field_syntax.md +++ b/test/snapshots/records/record_mixed_field_syntax.md @@ -84,6 +84,5 @@ NO CHANGE ~~~ # TYPES ~~~clojure -(expr (type "{ age: a, balance: Error, email: Error, name: Error, status: Str } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) +(expr (type "{ age: a, balance: Error, email: Error, name: Error, status: Str } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]")) ~~~ diff --git a/test/snapshots/records/record_mixed_types.md b/test/snapshots/records/record_mixed_types.md index e88d61f9be..12b3a02870 100644 --- a/test/snapshots/records/record_mixed_types.md +++ b/test/snapshots/records/record_mixed_types.md @@ -72,10 +72,5 @@ NO CHANGE ~~~ # TYPES ~~~clojure -(expr (type "{ active: Error, age: a, balance: b, name: Str, scores: List(c) } - where [ - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)]), - ]")) +(expr (type "{ active: Error, age: a, balance: b, name: Str, scores: List(c) } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)])]")) ~~~ diff --git a/test/snapshots/records/record_nested.md b/test/snapshots/records/record_nested.md index 8ed0af5c93..129c0d1c0a 100644 --- a/test/snapshots/records/record_nested.md +++ b/test/snapshots/records/record_nested.md @@ -137,10 +137,5 @@ EndOfFile, ~~~ # TYPES ~~~clojure -(expr (type "{ address: { city: Str, coordinates: { lat: a, lng: b }, street: Str }, contact: { email: Str, phone: { home: Str, work: Str } }, person: { age: c, name: Str } } - where [ - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)]), - ]")) +(expr (type "{ address: { city: Str, coordinates: { lat: a, lng: b }, street: Str }, contact: { email: Str, phone: { home: Str, work: Str } }, person: { age: c, name: Str } } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)])]")) ~~~ diff --git a/test/snapshots/records/record_with_complex_types.md b/test/snapshots/records/record_with_complex_types.md index 5358fb67f9..3f50fc2c90 100644 --- a/test/snapshots/records/record_with_complex_types.md +++ b/test/snapshots/records/record_with_complex_types.md @@ -234,10 +234,5 @@ EndOfFile, ~~~ # TYPES ~~~clojure -(expr (type "{ callback: a -> a, metadata: [Ok({ permissions: List([Read, Write, Admin, .._others]), tags: List(Str) }), .._others2], name: Str, nested: { items: List([Some(Str), ..[None, .._others3]]), result: [Success({ data: List(b), timestamp: Str }), .._others4] }, preferences: { notifications: [Email(Str), .._others5], theme: [Dark, .._others6] }, scores: List(c), status: [Active({ since: Str }), .._others7] } - where [ - a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), - b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), - c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)]), - ]")) +(expr (type "{ callback: a -> a, metadata: [Ok({ permissions: List([Read, Write, Admin, .._others]), tags: List(Str) }), .._others2], name: Str, nested: { items: List([Some(Str), ..[None, .._others3]]), result: [Success({ data: List(b), timestamp: Str }), .._others4] }, preferences: { notifications: [Email(Str), .._others5], theme: [Dark, .._others6] }, scores: List(c), status: [Active({ since: Str }), .._others7] } where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)]), b.from_numeral : Numeral -> Try(b, [InvalidNumeral(Str)]), c.from_numeral : Numeral -> Try(c, [InvalidNumeral(Str)])]")) ~~~ diff --git a/test/snapshots/static_dispatch/Adv.md b/test/snapshots/static_dispatch/Adv.md index adcb993f14..928bab252c 100644 --- a/test/snapshots/static_dispatch/Adv.md +++ b/test/snapshots/static_dispatch/Adv.md @@ -58,7 +58,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. @@ -72,7 +72,7 @@ This **update_strr** method is being called on a value whose type doesn't have t The value's type, which does not have a method named **update_strr**, is: - _Adv_ + Adv **Hint:** For this to work, the type would need to have a method named **update_strr** associated with it in the type's declaration. @@ -86,7 +86,7 @@ This **update** method is being called on a value whose type doesn't have that m The value's type, which does not have a method named **update**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **update** associated with it in the type's declaration. diff --git a/test/snapshots/static_dispatch/plus_operator_vs_method.md b/test/snapshots/static_dispatch/plus_operator_vs_method.md index 0bc0ca42a9..fc6dd9c029 100644 --- a/test/snapshots/static_dispatch/plus_operator_vs_method.md +++ b/test/snapshots/static_dispatch/plus_operator_vs_method.md @@ -36,7 +36,7 @@ result1 = a + b The value's type, which does not have a method named **plus**, is: - _MyType_ + MyType **Hint:**The **+** operator calls a method named **plus** on the value preceding it, passing the value after the operator as the one argument. @@ -50,7 +50,7 @@ result2 = a.plus(b) The value's type, which does not have a method named **plus**, is: - _MyType_ + MyType **Hint:** For this to work, the type would need to have a method named **plus** associated with it in the type's declaration. diff --git a/test/snapshots/string_interpolation_type_mismatch.md b/test/snapshots/string_interpolation_type_mismatch.md index 64cab497b0..bdc3a3d1cc 100644 --- a/test/snapshots/string_interpolation_type_mismatch.md +++ b/test/snapshots/string_interpolation_type_mismatch.md @@ -22,10 +22,12 @@ y = "value: ${x}" ^ It has the type: - _U8_ + + U8 But I expected it to be: - _Str_ + + Str # TOKENS ~~~zig diff --git a/test/snapshots/syntax_grab_bag.md b/test/snapshots/syntax_grab_bag.md index 76031a14bf..577b1cf875 100644 --- a/test/snapshots/syntax_grab_bag.md +++ b/test/snapshots/syntax_grab_bag.md @@ -844,7 +844,8 @@ This `if` condition needs to be a _Bool_: ^^^ Right now, it has the type: - _U64_ + + U64 Every `if` condition must evaluate to a _Bool_–either `True` or `False`. @@ -911,15 +912,15 @@ The pattern in the fourth branch of this `match` differs from previous ones: ^^^^^ The fourth pattern has this type: - _Str_ + + Str But all the previous patterns have this type: - _[Red, ..[Blue, Green, .._others2]]_ + + [Red, ..[Blue, Green, .._others2]] All patterns in an `match` must have compatible types. - - **UNUSED VALUE** This expression produces a value, but it's not being used: **syntax_grab_bag.md:1:1:1:1:** @@ -929,7 +930,8 @@ This expression produces a value, but it's not being used: ^ It has the type: - __d_ + + _d **TOO FEW ARGUMENTS** The function `match_time` expects 2 arguments, but 1 was provided: @@ -941,7 +943,8 @@ The function `match_time` expects 2 arguments, but 1 was provided: ``` The function has the signature: - _[Red, ..[Blue, Green, .._others2]], _arg -> Error_ + + [Red, ..[Blue, Green, .._others2]], _arg -> Error **TYPE MISMATCH** This expression is used in an unexpected way: @@ -952,10 +955,12 @@ This expression is used in an unexpected way: ^ It has the type: - _U64_ + + U64 But I expected it to be: - _Str_ + + Str **UNUSED VALUE** This expression produces a value, but it's not being used: @@ -966,7 +971,8 @@ This expression produces a value, but it's not being used: ^^^^^^^^^^^^^^^^^^^^^^^^^^^ It has the type: - __d_ + + _d **TYPE MISMATCH** This expression is used in an unexpected way: @@ -1028,10 +1034,12 @@ main! = |_| { # Yeah I can leave a comment here ``` It has the type: - _List(Error) => Error_ + + List(Error) => Error But the type annotation says it should have the type: - _List(Error) -> Error_ + + List(Error) -> Error # TOKENS ~~~zig diff --git a/test/snapshots/test_exact_pattern_crash.md b/test/snapshots/test_exact_pattern_crash.md index 653032da62..fddaa02f7c 100644 --- a/test/snapshots/test_exact_pattern_crash.md +++ b/test/snapshots/test_exact_pattern_crash.md @@ -57,7 +57,8 @@ The function `map_pair` expects 3 arguments, but 4 were provided: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The function has the signature: - _Pair(a, b), (a -> c), (b -> d) -> Pair(c, d)_ + + Pair(a, b), (a -> c), (b -> d) -> Pair(c, d) # TOKENS ~~~zig diff --git a/test/snapshots/test_instantiated_arg_mismatch.md b/test/snapshots/test_instantiated_arg_mismatch.md index 08fb1c1aeb..4d46b2728b 100644 --- a/test/snapshots/test_instantiated_arg_mismatch.md +++ b/test/snapshots/test_instantiated_arg_mismatch.md @@ -25,7 +25,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _Str_ + Str **Hint:** For this to work, the type would need to have a method named **from_numeral** associated with it in the type's declaration. diff --git a/test/snapshots/test_instantiated_return_crash.md b/test/snapshots/test_instantiated_return_crash.md index 7f9ce9b55a..819309a0bc 100644 --- a/test/snapshots/test_instantiated_return_crash.md +++ b/test/snapshots/test_instantiated_return_crash.md @@ -27,10 +27,12 @@ The first argument being passed to this function has the wrong type: ^^^^^^^^^ This argument has the type: - _List(Str)_ + + List(Str) But `f` needs the first argument to be: - _Str_ + + Str # TOKENS ~~~zig diff --git a/test/snapshots/test_instantiation_arity_mismatch.md b/test/snapshots/test_instantiation_arity_mismatch.md index 1cb1480790..82ca50d9db 100644 --- a/test/snapshots/test_instantiation_arity_mismatch.md +++ b/test/snapshots/test_instantiation_arity_mismatch.md @@ -24,7 +24,8 @@ The function `identity` expects 1 argument, but 2 were provided: ^^^^^^^^^^^^^^ The function has the signature: - _(a, b) -> (a, b)_ + + (a, b) -> (a, b) # TOKENS ~~~zig diff --git a/test/snapshots/test_nested_instantiation_crash.md b/test/snapshots/test_nested_instantiation_crash.md index 2fc132913f..720f82bf47 100644 --- a/test/snapshots/test_nested_instantiation_crash.md +++ b/test/snapshots/test_nested_instantiation_crash.md @@ -32,10 +32,12 @@ composed = |n| get_value(make_record(n)) ^^^^^^^^^^^^^^^^^^^^^^^^^ It has the type: - _List(a)_ + + List(a) But the type annotation says it should have the type: - _Str_ + + Str # TOKENS ~~~zig diff --git a/test/snapshots/test_tuple_instantiation_crash.md b/test/snapshots/test_tuple_instantiation_crash.md index fcd87d8c02..1f9e8a10bc 100644 --- a/test/snapshots/test_tuple_instantiation_crash.md +++ b/test/snapshots/test_tuple_instantiation_crash.md @@ -27,7 +27,8 @@ main = swap(1, 2) ^^^^^^^^^^ The function has the signature: - _(a, b) -> (b, a)_ + + (a, b) -> (b, a) # TOKENS ~~~zig diff --git a/test/snapshots/type_alias_parameterized.md b/test/snapshots/type_alias_parameterized.md index a0c1e4d1dc..16247d5855 100644 --- a/test/snapshots/type_alias_parameterized.md +++ b/test/snapshots/type_alias_parameterized.md @@ -26,7 +26,8 @@ main! = |_| swapPair(1, 2) ^^^^^^^^^^^^^^ The function has the signature: - _Pair(a, b) -> Pair(b, a)_ + + Pair(a, b) -> Pair(b, a) # TOKENS ~~~zig diff --git a/test/snapshots/type_annotation_missing_parens.md b/test/snapshots/type_annotation_missing_parens.md index 297dfb58d4..70f58019f9 100644 --- a/test/snapshots/type_annotation_missing_parens.md +++ b/test/snapshots/type_annotation_missing_parens.md @@ -43,7 +43,6 @@ nums : List U8 ^^^^ - # TOKENS ~~~zig LowerIdent,OpColon,UpperIdent,UpperIdent, diff --git a/test/snapshots/type_app_complex_nested.md b/test/snapshots/type_app_complex_nested.md index c8cc3239ae..d15fa46aca 100644 --- a/test/snapshots/type_app_complex_nested.md +++ b/test/snapshots/type_app_complex_nested.md @@ -112,7 +112,6 @@ ComplexType(a, b) : Try(List(Maybe(a)), Dict(Str, Error(b))) ^^^^^^^^^^^^^^^^^^^ - **TOO MANY ARGS** The type _Dict_ expects 0 arguments, but got 2 instead. **type_app_complex_nested.md:4:38:4:58:** @@ -122,7 +121,6 @@ processComplex : Try(List(Maybe(a)), Dict(Str, Error(_b))) -> List(a) ^^^^^^^^^^^^^^^^^^^^ - # TOKENS ~~~zig KwApp,OpenSquare,LowerIdent,CloseSquare,OpenCurly,LowerIdent,OpColon,KwPlatform,StringStart,StringPart,StringEnd,CloseCurly, diff --git a/test/snapshots/type_app_multiple_args.md b/test/snapshots/type_app_multiple_args.md index 03210e8493..4e9dc924d2 100644 --- a/test/snapshots/type_app_multiple_args.md +++ b/test/snapshots/type_app_multiple_args.md @@ -38,7 +38,6 @@ processDict : Dict(Str, U64) -> List(Str) ^^^^^^^^^^^^^^ - # TOKENS ~~~zig KwApp,OpenSquare,LowerIdent,CloseSquare,OpenCurly,LowerIdent,OpColon,KwPlatform,StringStart,StringPart,StringEnd,CloseCurly, diff --git a/test/snapshots/type_app_with_vars.md b/test/snapshots/type_app_with_vars.md index 1a774d2cc6..9434663488 100644 --- a/test/snapshots/type_app_with_vars.md +++ b/test/snapshots/type_app_with_vars.md @@ -24,7 +24,8 @@ main! = |_| mapList([1,2,3,4,5]) ^^^^^^^^^^^^^^^^^^^^ The function has the signature: - _List(a), (a -> b) -> List(b)_ + + List(a), (a -> b) -> List(b) # TOKENS ~~~zig diff --git a/test/snapshots/type_comprehensive_scope.md b/test/snapshots/type_comprehensive_scope.md index 03c06402e3..b7fb6d5b00 100644 --- a/test/snapshots/type_comprehensive_scope.md +++ b/test/snapshots/type_comprehensive_scope.md @@ -116,7 +116,6 @@ MyDict : Dict(Str, U64) ^^^^^^^^^^^^^^ - # TOKENS ~~~zig UpperIdent,OpColon,UpperIdent, diff --git a/test/snapshots/type_local_scope_vars.md b/test/snapshots/type_local_scope_vars.md index f845d1e001..96554d6be3 100644 --- a/test/snapshots/type_local_scope_vars.md +++ b/test/snapshots/type_local_scope_vars.md @@ -50,10 +50,12 @@ The first argument being passed to this function has the wrong type: ^ This argument has the type: - _b_ + + b But `f` needs the first argument to be: - _a_ + + a # TOKENS ~~~zig diff --git a/test/snapshots/type_record_basic.md b/test/snapshots/type_record_basic.md index abffb5169a..d8ac546de3 100644 --- a/test/snapshots/type_record_basic.md +++ b/test/snapshots/type_record_basic.md @@ -24,11 +24,13 @@ main! = |_| getName({namee: "luke", age:21}) ^^^^^^^^^^^^^^^^^^^^^^^ This argument has the type: - _{ age: a, namee: Str } - where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]_ + + { age: a, namee: Str } + where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])] But `getName` needs the first argument to be: - _{ age: U64, name: Str }_ + + { age: U64, name: Str } # TOKENS ~~~zig diff --git a/test/snapshots/type_var_mismatch.md b/test/snapshots/type_var_mismatch.md index db76757c96..f867083acb 100644 --- a/test/snapshots/type_var_mismatch.md +++ b/test/snapshots/type_var_mismatch.md @@ -35,7 +35,7 @@ This **from_numeral** method is being called on a value whose type doesn't have The value's type, which does not have a method named **from_numeral**, is: - _item_ + item **Hint:** Did you forget to specify **from_numeral** in the type annotation? diff --git a/test/snapshots/type_var_underscore_conventions.md b/test/snapshots/type_var_underscore_conventions.md index 9f7aa0251d..ac480f2cda 100644 --- a/test/snapshots/type_var_underscore_conventions.md +++ b/test/snapshots/type_var_underscore_conventions.md @@ -105,10 +105,12 @@ starting_dollar = |list| "default" ^^^^^^^^^ It has the type: - _Str_ + + Str But the type annotation says it should have the type: - _$elem_ + + $elem # TOKENS ~~~zig diff --git a/test/snapshots/where_clause/where_clauses_10.md b/test/snapshots/where_clause/where_clauses_10.md index 26930714a6..0c8edf76ca 100644 --- a/test/snapshots/where_clause/where_clauses_10.md +++ b/test/snapshots/where_clause/where_clauses_10.md @@ -38,7 +38,6 @@ The where clause syntax _Decode_ is not supported: This syntax was used for abilities, which have been removed from Roc. Use method constraints like `where [a.methodName(args) -> ret]` instead. - # TOKENS ~~~zig KwImport,UpperIdent,KwExposing,OpenSquare,UpperIdent,CloseSquare, diff --git a/test/snapshots/where_clause/where_clauses_4.md b/test/snapshots/where_clause/where_clauses_4.md index 255fcec691..866806f928 100644 --- a/test/snapshots/where_clause/where_clauses_4.md +++ b/test/snapshots/where_clause/where_clauses_4.md @@ -36,7 +36,6 @@ The where clause syntax _Decode_ is not supported: This syntax was used for abilities, which have been removed from Roc. Use method constraints like `where [a.methodName(args) -> ret]` instead. - # TOKENS ~~~zig KwImport,UpperIdent,KwExposing,OpenSquare,UpperIdent,CloseSquare, diff --git a/test/snapshots/where_clause/where_clauses_serde_example.md b/test/snapshots/where_clause/where_clauses_serde_example.md index 225a0f0f3f..52d0bfe848 100644 --- a/test/snapshots/where_clause/where_clauses_serde_example.md +++ b/test/snapshots/where_clause/where_clauses_serde_example.md @@ -90,9 +90,7 @@ NO CHANGE ~~~clojure (inferred-types (defs - (patt (type "List(U8) -> Try(a, [DecodeErr]) - where [a.decode : List(U8) -> Try(a, [DecodeErr])]"))) + (patt (type "List(U8) -> Try(a, [DecodeErr]) where [a.decode : List(U8) -> Try(a, [DecodeErr])]"))) (expressions - (expr (type "List(U8) -> Try(a, [DecodeErr]) - where [a.decode : List(U8) -> Try(a, [DecodeErr])]")))) + (expr (type "List(U8) -> Try(a, [DecodeErr]) where [a.decode : List(U8) -> Try(a, [DecodeErr])]")))) ~~~