From 7a459560ea2576175705e69875085b39ebb85af1 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 17 Nov 2025 10:27:09 -0500 Subject: [PATCH] Fix snapshots --- src/snapshot_tool/main.zig | 29 ++--------- test/snapshots/can_import_comprehensive.md | 19 +++++++ test/snapshots/can_import_exposing_types.md | 5 +- test/snapshots/let_polymorphism_lists.md | 51 +++---------------- .../snapshots/match_expr/complex_list_tags.md | 17 +------ test/snapshots/match_expr/nested_patterns.md | 19 ++----- test/snapshots/simple_external_lookup.md | 21 ++------ test/snapshots/type_var_namespace.md | 32 ++++++------ 8 files changed, 56 insertions(+), 137 deletions(-) diff --git a/src/snapshot_tool/main.zig b/src/snapshot_tool/main.zig index a9729cc5ed..2af73c72f8 100644 --- a/src/snapshot_tool/main.zig +++ b/src/snapshot_tool/main.zig @@ -1221,37 +1221,14 @@ fn processSnapshotContent( .builtin_module = config.builtin_module, }; - // Auto-inject Bool, Try, Str, Dict, and Set as available imports (if they're loaded) + // Auto-inject builtin types (Bool, Try, List, Dict, Set, Str, and numeric types) as available imports // This makes them available without needing explicit `import` statements in tests var module_envs = std.AutoHashMap(base.Ident.Idx, Can.AutoImportedType).init(allocator); defer module_envs.deinit(); - // Register each builtin type individually with its statement index - // They all point to the same Builtin module env - // Note: Str is NOT added because it's handled as a primitive builtin type - // in TypeAnno.Builtin.fromBytes() and should never go through module_envs + // Use the shared populateModuleEnvs function to ensure consistency with production code if (config.builtin_module) |builtin_env| { - const bool_ident = try can_ir.common.idents.insert(allocator, base.Ident.for_text("Bool")); - const try_ident = try can_ir.common.idents.insert(allocator, base.Ident.for_text("Try")); - const dict_ident = try can_ir.common.idents.insert(allocator, base.Ident.for_text("Dict")); - const set_ident = try can_ir.common.idents.insert(allocator, base.Ident.for_text("Set")); - - try module_envs.put(bool_ident, .{ - .env = builtin_env, - .statement_idx = config.builtin_indices.bool_type, - }); - try module_envs.put(try_ident, .{ - .env = builtin_env, - .statement_idx = config.builtin_indices.try_type, - }); - try module_envs.put(dict_ident, .{ - .env = builtin_env, - .statement_idx = config.builtin_indices.dict_type, - }); - try module_envs.put(set_ident, .{ - .env = builtin_env, - .statement_idx = config.builtin_indices.set_type, - }); + try Can.populateModuleEnvs(&module_envs, can_ir, builtin_env, config.builtin_indices); } var czer = try Can.init(can_ir, &parse_ast, &module_envs); diff --git a/test/snapshots/can_import_comprehensive.md b/test/snapshots/can_import_comprehensive.md index a23fbebae7..c8b914a426 100644 --- a/test/snapshots/can_import_comprehensive.md +++ b/test/snapshots/can_import_comprehensive.md @@ -42,6 +42,7 @@ main = { # EXPECTED MODULE NOT FOUND - can_import_comprehensive.md:1:1:1:17 MODULE NOT FOUND - can_import_comprehensive.md:2:1:2:48 +DUPLICATE DEFINITION - can_import_comprehensive.md:3:1:3:27 MODULE NOT FOUND - can_import_comprehensive.md:3:1:3:27 UNDEFINED VARIABLE - can_import_comprehensive.md:6:14:6:22 UNDEFINED VARIABLE - can_import_comprehensive.md:7:14:7:23 @@ -74,6 +75,24 @@ import http.Client as Http exposing [get, post] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**DUPLICATE DEFINITION** +The name `Str` is being redeclared in this scope. + +The redeclaration is here: +**can_import_comprehensive.md:3:1:3:27:** +```roc +import utils.String as Str +``` +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +But `Str` was already defined here: +**can_import_comprehensive.md:1:1:1:1:** +```roc +import json.Json +``` +^ + + **MODULE NOT FOUND** The module `utils.String` was not found in this Roc project. diff --git a/test/snapshots/can_import_exposing_types.md b/test/snapshots/can_import_exposing_types.md index 7d681fc7ab..83cb468eeb 100644 --- a/test/snapshots/can_import_exposing_types.md +++ b/test/snapshots/can_import_exposing_types.md @@ -311,9 +311,6 @@ processData : Config, List(Value) -> Try(List(Value), Error) **DOES NOT EXIST** `List.mapTry` does not exist. -`List` is in scope, but it has no associated `mapTry`. - -It's referenced here: **can_import_exposing_types.md:22:5:22:16:** ```roc List.mapTry( @@ -801,7 +798,7 @@ combineTrys = |jsonTry, httpStatus| (p-assign (ident "config")) (p-assign (ident "values"))) (e-call - (e-runtime-error (tag "nested_value_not_found")) + (e-runtime-error (tag "qualified_ident_does_not_exist")) (e-lookup-local (p-assign (ident "values"))) (e-closure diff --git a/test/snapshots/let_polymorphism_lists.md b/test/snapshots/let_polymorphism_lists.md index 8014e29ecf..c48873e380 100644 --- a/test/snapshots/let_polymorphism_lists.md +++ b/test/snapshots/let_polymorphism_lists.md @@ -45,9 +45,6 @@ PARSE ERROR - let_polymorphism_lists.md:14:32:14:45 UNRECOGNIZED SYNTAX - let_polymorphism_lists.md:12:16:12:27 UNRECOGNIZED SYNTAX - let_polymorphism_lists.md:13:16:13:27 UNRECOGNIZED SYNTAX - let_polymorphism_lists.md:14:18:14:31 -DOES NOT EXIST - let_polymorphism_lists.md:25:12:25:20 -DOES NOT EXIST - let_polymorphism_lists.md:26:12:26:20 -DOES NOT EXIST - let_polymorphism_lists.md:27:12:27:20 # PROBLEMS **UNEXPECTED TOKEN IN EXPRESSION** The token **+** is not expected in an expression. @@ -148,45 +145,6 @@ all_float_list = float_list ++ my_empty_list This might be a syntax error, an unsupported language feature, or a typo. -**DOES NOT EXIST** -`List.len` does not exist. - -`List` is in scope, but it has no associated `len`. - -It's referenced here: -**let_polymorphism_lists.md:25:12:25:20:** -```roc - len1 = List.len(all_int_list) -``` - ^^^^^^^^ - - -**DOES NOT EXIST** -`List.len` does not exist. - -`List` is in scope, but it has no associated `len`. - -It's referenced here: -**let_polymorphism_lists.md:26:12:26:20:** -```roc - len2 = List.len(all_str_list) -``` - ^^^^^^^^ - - -**DOES NOT EXIST** -`List.len` does not exist. - -`List` is in scope, but it has no associated `len`. - -It's referenced here: -**let_polymorphism_lists.md:27:12:27:20:** -```roc - len3 = List.len(all_float_list) -``` - ^^^^^^^^ - - # TOKENS ~~~zig KwApp,OpenSquare,LowerIdent,CloseSquare,OpenCurly,LowerIdent,OpColon,KwPlatform,StringStart,StringPart,StringEnd,CloseCurly, @@ -413,19 +371,22 @@ main = |_| { (s-let (p-assign (ident "len1")) (e-call - (e-runtime-error (tag "nested_value_not_found")) + (e-lookup-external + (builtin)) (e-lookup-local (p-assign (ident "all_int_list"))))) (s-let (p-assign (ident "len2")) (e-call - (e-runtime-error (tag "nested_value_not_found")) + (e-lookup-external + (builtin)) (e-lookup-local (p-assign (ident "all_str_list"))))) (s-let (p-assign (ident "len3")) (e-call - (e-runtime-error (tag "nested_value_not_found")) + (e-lookup-external + (builtin)) (e-lookup-local (p-assign (ident "all_float_list"))))) (e-binop (op "add") diff --git a/test/snapshots/match_expr/complex_list_tags.md b/test/snapshots/match_expr/complex_list_tags.md index 90a7a03fd3..8b65d3bbd6 100644 --- a/test/snapshots/match_expr/complex_list_tags.md +++ b/test/snapshots/match_expr/complex_list_tags.md @@ -19,7 +19,6 @@ UNDEFINED VARIABLE - complex_list_tags.md:1:7:1:13 DOES NOT EXIST - complex_list_tags.md:3:42:3:51 DOES NOT EXIST - complex_list_tags.md:3:59:3:68 DOES NOT EXIST - complex_list_tags.md:4:59:4:68 -DOES NOT EXIST - complex_list_tags.md:4:69:4:77 DOES NOT EXIST - complex_list_tags.md:5:62:5:71 DOES NOT EXIST - complex_list_tags.md:5:79:5:88 DOES NOT EXIST - complex_list_tags.md:5:101:5:110 @@ -71,19 +70,6 @@ match events { ^^^^^^^^^ -**DOES NOT EXIST** -`List.len` does not exist. - -`List` is in scope, but it has no associated `len`. - -It's referenced here: -**complex_list_tags.md:4:69:4:77:** -```roc - [KeyPress(key), .. as rest] => "key ${key} pressed, ${Num.toStr(List.len(rest))} more events" -``` - ^^^^^^^^ - - **DOES NOT EXIST** `Num.toStr` does not exist. @@ -345,7 +331,8 @@ match events { (e-call (e-runtime-error (tag "qualified_ident_does_not_exist")) (e-call - (e-runtime-error (tag "nested_value_not_found")) + (e-lookup-external + (builtin)) (e-lookup-local (p-assign (ident "rest"))))) (e-literal (string " more events"))))) diff --git a/test/snapshots/match_expr/nested_patterns.md b/test/snapshots/match_expr/nested_patterns.md index df48208e59..558a73d152 100644 --- a/test/snapshots/match_expr/nested_patterns.md +++ b/test/snapshots/match_expr/nested_patterns.md @@ -14,7 +14,6 @@ match data { ~~~ # EXPECTED UNDEFINED VARIABLE - nested_patterns.md:1:7:1:11 -DOES NOT EXIST - nested_patterns.md:2:57:2:65 # PROBLEMS **UNDEFINED VARIABLE** Nothing is named `data` in this scope. @@ -27,19 +26,6 @@ match data { ^^^^ -**DOES NOT EXIST** -`List.len` does not exist. - -`List` is in scope, but it has no associated `len`. - -It's referenced here: -**nested_patterns.md:2:57:2:65:** -```roc - Container({ items: [First(x), .. as rest] }) => x + List.len(rest) -``` - ^^^^^^^^ - - # TOKENS ~~~zig KwMatch,LowerIdent,OpenCurly, @@ -114,7 +100,8 @@ match data { (e-lookup-local (p-assign (ident "x"))) (e-call - (e-runtime-error (tag "nested_value_not_found")) + (e-lookup-external + (builtin)) (e-lookup-local (p-assign (ident "rest"))))))) (branch @@ -143,5 +130,5 @@ match data { ~~~ # TYPES ~~~clojure -(expr (type "Error")) +(expr (type "Num(Int(Unsigned64))")) ~~~ diff --git a/test/snapshots/simple_external_lookup.md b/test/snapshots/simple_external_lookup.md index 1672681a7d..83d2c573e3 100644 --- a/test/snapshots/simple_external_lookup.md +++ b/test/snapshots/simple_external_lookup.md @@ -8,21 +8,9 @@ type=expr List.map ~~~ # EXPECTED -DOES NOT EXIST - simple_external_lookup.md:1:1:1:9 +NIL # PROBLEMS -**DOES NOT EXIST** -`List.map` does not exist. - -`List` is in scope, but it has no associated `map`. - -It's referenced here: -**simple_external_lookup.md:1:1:1:9:** -```roc -List.map -``` -^^^^^^^^ - - +NIL # TOKENS ~~~zig UpperIdent,NoSpaceDotLowerIdent, @@ -38,9 +26,10 @@ NO CHANGE ~~~ # CANONICALIZE ~~~clojure -(e-runtime-error (tag "nested_value_not_found")) +(e-lookup-external + (builtin)) ~~~ # TYPES ~~~clojure -(expr (type "Error")) +(expr (type "List(a), (a -> b) -> List(b)")) ~~~ diff --git a/test/snapshots/type_var_namespace.md b/test/snapshots/type_var_namespace.md index a1c062735d..28322ed392 100644 --- a/test/snapshots/type_var_namespace.md +++ b/test/snapshots/type_var_namespace.md @@ -24,9 +24,9 @@ main! = |_| {} ~~~ # EXPECTED UNEXPECTED TOKEN IN EXPRESSION - type_var_namespace.md:11:31:11:33 -DOES NOT EXIST - type_var_namespace.md:11:14:11:24 UNRECOGNIZED SYNTAX - type_var_namespace.md:11:31:11:33 DOES NOT EXIST - type_var_namespace.md:11:34:11:49 +TYPE MISMATCH - type_var_namespace.md:11:14:11:30 # PROBLEMS **UNEXPECTED TOKEN IN EXPRESSION** The token **|>** is not expected in an expression. @@ -39,19 +39,6 @@ Expressions can be identifiers, literals, function calls, or operators. ^^ -**DOES NOT EXIST** -`List.first` does not exist. - -`List` is in scope, but it has no associated `first`. - -It's referenced here: -**type_var_namespace.md:11:14:11:24:** -```roc - result = List.first(list) |> Try.withDefault(elem) -``` - ^^^^^^^^^^ - - **UNRECOGNIZED SYNTAX** I don't recognize this syntax. @@ -73,6 +60,20 @@ This might be a syntax error, an unsupported language feature, or a typo. ^^^^^^^^^^^^^^^ +**TYPE MISMATCH** +This expression is used in an unexpected way: +**type_var_namespace.md:11:14:11:30:** +```roc + result = List.first(list) |> Try.withDefault(elem) +``` + ^^^^^^^^^^^^^^^^ + +It has the type: + _Try(elem, [ListWasEmpty])_ + +But the type annotation says it should have the type: + _elem_ + # TOKENS ~~~zig KwApp,OpenSquare,LowerIdent,CloseSquare,OpenCurly,LowerIdent,OpColon,KwPlatform,StringStart,StringPart,StringEnd,CloseCurly, @@ -171,7 +172,8 @@ main! = |_| {} (s-let (p-assign (ident "result")) (e-call - (e-runtime-error (tag "nested_value_not_found")) + (e-lookup-external + (builtin)) (e-lookup-local (p-assign (ident "list"))))) (s-expr