From 7900cd31cd08a2de7846b4b3833bb85ae43da6e2 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 21 Oct 2025 21:51:31 -0400 Subject: [PATCH] Revise error message for missing qualified types --- src/canonicalize/Diagnostic.zig | 16 +++++++++++++--- test/snapshots/can_import_nested_modules.md | 6 +++--- test/snapshots/multi_qualified_import.md | 4 ++-- .../nominal_undefined_deeply_nested_tag.md | 2 +- .../snapshots/qualified_type_canonicalization.md | 6 +++--- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/canonicalize/Diagnostic.zig b/src/canonicalize/Diagnostic.zig index 232f258de9..99fceb5f20 100644 --- a/src/canonicalize/Diagnostic.zig +++ b/src/canonicalize/Diagnostic.zig @@ -889,9 +889,19 @@ pub const Diagnostic = union(enum) { ) !Report { var report = Report.init(allocator, "UNDECLARED TYPE", .runtime_error); const owned_type_name = try report.addOwnedString(type_name); - try report.document.addReflowingText("The type "); - try report.document.addType(owned_type_name); - try report.document.addReflowingText(" is not declared in this scope."); + + // Check if this looks like a qualified type (contains dots) + const has_dots = std.mem.indexOfScalar(u8, type_name, '.') != null; + + if (has_dots) { + try report.document.addReflowingText("Cannot resolve qualified type "); + try report.document.addType(owned_type_name); + try report.document.addReflowingText("."); + } else { + try report.document.addReflowingText("The type "); + try report.document.addType(owned_type_name); + try report.document.addReflowingText(" is not declared in this scope."); + } try report.document.addLineBreak(); try report.document.addLineBreak(); diff --git a/test/snapshots/can_import_nested_modules.md b/test/snapshots/can_import_nested_modules.md index 2aec43b7c7..d066cb1f25 100644 --- a/test/snapshots/can_import_nested_modules.md +++ b/test/snapshots/can_import_nested_modules.md @@ -82,7 +82,7 @@ import utils.String.Format exposing [padLeft] **UNDECLARED TYPE** -The type _Config.Settings_ is not declared in this scope. +Cannot resolve qualified type _Config.Settings_. This type is referenced here: **can_import_nested_modules.md:6:21:6:30:** @@ -126,7 +126,7 @@ authenticate = |user, pass| HttpAuth.login(user, pass) **UNDECLARED TYPE** -The type _Config.Parser.Advanced_ is not declared in this scope. +Cannot resolve qualified type _Config.Parser.Advanced_. This type is referenced here: **can_import_nested_modules.md:14:28:14:37:** @@ -137,7 +137,7 @@ processData : Config.Parser.Advanced, Str -> Result(Str, Config.Parser.Error) **UNDECLARED TYPE** -The type _Config.Parser.Error_ is not declared in this scope. +Cannot resolve qualified type _Config.Parser.Error_. This type is referenced here: **can_import_nested_modules.md:14:71:14:77:** diff --git a/test/snapshots/multi_qualified_import.md b/test/snapshots/multi_qualified_import.md index 70ae4112e3..357b0898da 100644 --- a/test/snapshots/multi_qualified_import.md +++ b/test/snapshots/multi_qualified_import.md @@ -157,7 +157,7 @@ json_encoder = Json.Core.Utf8.defaultEncoder **UNDECLARED TYPE** -The type _json.Core.Utf8.Encoder_ is not declared in this scope. +Cannot resolve qualified type _json.Core.Utf8.Encoder_. This type is referenced here: **multi_qualified_import.md:7:25:7:33:** @@ -180,7 +180,7 @@ process = |encoder| "processing" **UNDECLARED TYPE** -The type _json.Core.Utf8.EncodedData_ is not declared in this scope. +Cannot resolve qualified type _json.Core.Utf8.EncodedData_. This type is referenced here: **multi_qualified_import.md:11:22:11:34:** diff --git a/test/snapshots/nominal/nominal_undefined_deeply_nested_tag.md b/test/snapshots/nominal/nominal_undefined_deeply_nested_tag.md index fa14460621..23f1711556 100644 --- a/test/snapshots/nominal/nominal_undefined_deeply_nested_tag.md +++ b/test/snapshots/nominal/nominal_undefined_deeply_nested_tag.md @@ -15,7 +15,7 @@ x = Foo.Bar.Baz.X UNDECLARED TYPE - nominal_undefined_deeply_nested_tag.md:5:12:5:16 # PROBLEMS **UNDECLARED TYPE** -The type _Foo.Bar.Baz_ is not declared in this scope. +Cannot resolve qualified type _Foo.Bar.Baz_. This type is referenced here: **nominal_undefined_deeply_nested_tag.md:5:12:5:16:** diff --git a/test/snapshots/qualified_type_canonicalization.md b/test/snapshots/qualified_type_canonicalization.md index 3b829b330a..7a245c3903 100644 --- a/test/snapshots/qualified_type_canonicalization.md +++ b/test/snapshots/qualified_type_canonicalization.md @@ -176,7 +176,7 @@ aliasedQualified : ExtMod.DataType **UNDECLARED TYPE** -The type _ExtMod.DataType_ is not declared in this scope. +Cannot resolve qualified type _ExtMod.DataType_. This type is referenced here: **qualified_type_canonicalization.md:19:26:19:35:** @@ -187,7 +187,7 @@ aliasedQualified = ExtMod.DataType.Default **UNDECLARED TYPE** -The type _ModuleA.ModuleB.TypeC_ is not declared in this scope. +Cannot resolve qualified type _ModuleA.ModuleB.TypeC_. This type is referenced here: **qualified_type_canonicalization.md:22:38:22:44:** @@ -298,7 +298,7 @@ transform : Result.Result(Color.RGB, ExtMod.Error) -> ModuleA.ModuleB.TypeC **UNDECLARED TYPE** -The type _ModuleA.ModuleB.TypeC_ is not declared in this scope. +Cannot resolve qualified type _ModuleA.ModuleB.TypeC_. This type is referenced here: **qualified_type_canonicalization.md:39:70:39:76:**