From 4ff46a571d8a33d278ee6357ea96362f02ac37af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbyne=CC=8Ck=20Jur=CC=8Cica?= Date: Sat, 6 Jun 2026 12:04:08 +0200 Subject: [PATCH] rephrase 'did you mean one of these' compiler hint for singular scenario --- compiler-core/src/error.rs | 7 ++++++- ..._type___tests__errors__same_imports_multiple_times.snap | 6 +++--- ...dules_from_the_same_package_with_internal_function.snap | 2 +- ..._the_same_package_with_internal_record_constructor.snap | 2 +- ...t_modules_from_the_same_package_with_internal_type.snap | 2 +- ..._modules_from_the_same_package_with_internal_value.snap | 2 +- ...n_variable_suggest_modules_imported_using_an_alias.snap | 2 +- ...wn_variable_suggest_modules_with_multiple_segments.snap | 2 +- ..._modules_with_public_function_with_correct_arity_1.snap | 2 +- ..._modules_with_public_function_with_correct_arity_2.snap | 2 +- ..._modules_with_public_function_with_correct_arity_3.snap | 2 +- ..._modules_with_public_function_with_correct_arity_4.snap | 2 +- ...with_correct_arity_even_if_arguments_type_mismatch.snap | 2 +- ..._with_public_record_constructor_with_correct_arity.snap | 2 +- ..._unknown_variable_suggest_modules_with_public_type.snap | 2 +- ...known_variable_suggest_modules_with_public_value_1.snap | 2 +- ...known_variable_suggest_modules_with_public_value_2.snap | 2 +- 17 files changed, 24 insertions(+), 19 deletions(-) diff --git a/compiler-core/src/error.rs b/compiler-core/src/error.rs index 09612444f..c1229c916 100644 --- a/compiler-core/src/error.rs +++ b/compiler-core/src/error.rs @@ -3528,7 +3528,12 @@ but no type in scope with that name." // If there are some suggestions about public values in imported // modules put a "did you mean" text after the main message if !possible_modules.is_empty() { - text.push_str("\nDid you mean one of these:\n\n"); + let message = if possible_modules.len() == 1 { + "\nDid you mean:\n\n" + } else { + "\nDid you mean one of these:\n\n" + }; + text.push_str(message); for module_name in possible_modules { text.push_str(&format!(" - {module_name}.{name}\n")) } diff --git a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__same_imports_multiple_times.snap b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__same_imports_multiple_times.snap index 134720639..e4a62ef41 100644 --- a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__same_imports_multiple_times.snap +++ b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__same_imports_multiple_times.snap @@ -7,14 +7,14 @@ expression: "\n import gleam/wibble.{wobble}\n import gleam/wibble pub fn wobble() { 1 } pub fn zoo() { 1 } - + -- main.gleam import gleam/wibble.{wobble} import gleam/wibble.{zoo} pub fn go() { wobble() + zoo() } - + ----- ERROR error: Duplicate import @@ -35,6 +35,6 @@ error: Unknown variable │ ^^^ The name `zoo` is not in scope here. -Did you mean one of these: +Did you mean: - wibble.zoo diff --git a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_from_the_same_package_with_internal_function.snap b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_from_the_same_package_with_internal_function.snap index b4fbbe4f6..d9d327e4c 100644 --- a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_from_the_same_package_with_internal_function.snap +++ b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_from_the_same_package_with_internal_function.snap @@ -28,6 +28,6 @@ error: Unknown variable │ ^^^ The name `add` is not in scope here. -Did you mean one of these: +Did you mean: - module.add diff --git a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_from_the_same_package_with_internal_record_constructor.snap b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_from_the_same_package_with_internal_record_constructor.snap index d3769c70c..30650eea5 100644 --- a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_from_the_same_package_with_internal_record_constructor.snap +++ b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_from_the_same_package_with_internal_record_constructor.snap @@ -28,6 +28,6 @@ error: Unknown variable │ ^^^^^^^^ The custom type variant constructor `MyRecord` is not in scope here. -Did you mean one of these: +Did you mean: - module.MyRecord diff --git a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_from_the_same_package_with_internal_type.snap b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_from_the_same_package_with_internal_type.snap index 4c185cc01..448e556fe 100644 --- a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_from_the_same_package_with_internal_type.snap +++ b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_from_the_same_package_with_internal_type.snap @@ -28,6 +28,6 @@ error: Unknown variable │ ^^^ The custom type variant constructor `One` is not in scope here. -Did you mean one of these: +Did you mean: - module.One diff --git a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_from_the_same_package_with_internal_value.snap b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_from_the_same_package_with_internal_value.snap index 8f40fbb5e..f581bbe08 100644 --- a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_from_the_same_package_with_internal_value.snap +++ b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_from_the_same_package_with_internal_value.snap @@ -25,6 +25,6 @@ error: Unknown variable │ ^^^ The name `one` is not in scope here. -Did you mean one of these: +Did you mean: - module.one diff --git a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_imported_using_an_alias.snap b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_imported_using_an_alias.snap index 0e3cf948d..948113ad7 100644 --- a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_imported_using_an_alias.snap +++ b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_imported_using_an_alias.snap @@ -27,6 +27,6 @@ error: Unknown variable │ ^^^ The name `add` is not in scope here. -Did you mean one of these: +Did you mean: - wibble.add diff --git a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_multiple_segments.snap b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_multiple_segments.snap index 90ac1a941..17e11c69e 100644 --- a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_multiple_segments.snap +++ b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_multiple_segments.snap @@ -27,6 +27,6 @@ error: Unknown variable │ ^^^ The name `add` is not in scope here. -Did you mean one of these: +Did you mean: - module.add diff --git a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_function_with_correct_arity_1.snap b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_function_with_correct_arity_1.snap index 7bae30336..ba73600fa 100644 --- a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_function_with_correct_arity_1.snap +++ b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_function_with_correct_arity_1.snap @@ -26,6 +26,6 @@ error: Unknown variable │ ^^^ The name `add` is not in scope here. -Did you mean one of these: +Did you mean: - module.add diff --git a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_function_with_correct_arity_2.snap b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_function_with_correct_arity_2.snap index a25c3fe6d..f1a73c9e2 100644 --- a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_function_with_correct_arity_2.snap +++ b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_function_with_correct_arity_2.snap @@ -26,6 +26,6 @@ error: Unknown variable │ ^^^ The name `add` is not in scope here. -Did you mean one of these: +Did you mean: - module.add diff --git a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_function_with_correct_arity_3.snap b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_function_with_correct_arity_3.snap index 17a52b854..7b307d46f 100644 --- a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_function_with_correct_arity_3.snap +++ b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_function_with_correct_arity_3.snap @@ -26,6 +26,6 @@ error: Unknown variable │ ^^^ The name `add` is not in scope here. -Did you mean one of these: +Did you mean: - module.add diff --git a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_function_with_correct_arity_4.snap b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_function_with_correct_arity_4.snap index 0d17ca9ed..e2979fbea 100644 --- a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_function_with_correct_arity_4.snap +++ b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_function_with_correct_arity_4.snap @@ -27,6 +27,6 @@ error: Unknown variable │ ^^^^^^ The name `wibble` is not in scope here. -Did you mean one of these: +Did you mean: - module.wibble diff --git a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_function_with_correct_arity_even_if_arguments_type_mismatch.snap b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_function_with_correct_arity_even_if_arguments_type_mismatch.snap index 83b9cc481..6cd021498 100644 --- a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_function_with_correct_arity_even_if_arguments_type_mismatch.snap +++ b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_function_with_correct_arity_even_if_arguments_type_mismatch.snap @@ -26,6 +26,6 @@ error: Unknown variable │ ^^^ The name `add` is not in scope here. -Did you mean one of these: +Did you mean: - module.add diff --git a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_record_constructor_with_correct_arity.snap b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_record_constructor_with_correct_arity.snap index 256a084b5..7a2766048 100644 --- a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_record_constructor_with_correct_arity.snap +++ b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_record_constructor_with_correct_arity.snap @@ -34,6 +34,6 @@ error: Unknown variable │ ^^^^^^^^ The custom type variant constructor `MyRecord` is not in scope here. -Did you mean one of these: +Did you mean: - moduletwo.MyRecord diff --git a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_type.snap b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_type.snap index 4629b3fa3..6e523edc9 100644 --- a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_type.snap +++ b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_type.snap @@ -27,6 +27,6 @@ error: Unknown variable │ ^^^ The custom type variant constructor `One` is not in scope here. -Did you mean one of these: +Did you mean: - module.One diff --git a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_value_1.snap b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_value_1.snap index 19df969d2..9990945ed 100644 --- a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_value_1.snap +++ b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_value_1.snap @@ -24,6 +24,6 @@ error: Unknown variable │ ^^^ The name `one` is not in scope here. -Did you mean one of these: +Did you mean: - module.one diff --git a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_value_2.snap b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_value_2.snap index e4bc0e953..674f297c1 100644 --- a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_value_2.snap +++ b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__unknown_variable_suggest_modules_with_public_value_2.snap @@ -27,6 +27,6 @@ error: Unknown variable │ ^^^ The name `add` is not in scope here. -Did you mean one of these: +Did you mean: - module.add -- 2.51.2