- Improve error message for Foo{} when Foo is not a generic type #2574.

This commit is contained in:
Christoffer Lerno
2025-11-16 23:54:19 +01:00
parent 1ea181524e
commit 06884720e5
5 changed files with 51 additions and 16 deletions

View File

@@ -5262,13 +5262,22 @@ Decl *sema_analyse_parameterized_identifier(SemaContext *c, Path *decl_path, con
unsigned parameter_count = vec_size(module->parameters);
ASSERT(parameter_count > 0);
if (parameter_count != vec_size(params))
unsigned count = vec_size(params);
if (parameter_count != count)
{
ASSERT_AT(span, vec_size(params));
sema_error_at(c, extend_span_with_token(params[0]->span, vectail(params)->span),
"The generic module expected %d arguments, but you supplied %d, did you make a mistake?",
parameter_count,
vec_size(params));
if (!count)
{
sema_error_at(c, invocation_span,
"'%s' must be instantiatied with generic module arguments inside the '{}', did you forget them?", name, (int)parameter_count);
}
else
{
sema_error_at(c, extend_span_with_token(params[0]->span, vectail(params)->span),
"The generic module expected %d argument(s), but you supplied %d, did you make a mistake?",
parameter_count,
vec_size(params));
}
return poisoned_decl;
}
if (!sema_generate_parameterized_name_to_scratch(c, module, params, true, was_recursive_ref)) return poisoned_decl;