Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/src/dmd/templatesem.d
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,10 @@ extern (D) MATCHpair deduceFunctionTemplateMatch(TemplateDeclaration td, Templat
}
if (fname && !foundName)
{
// This is where we need to handle the error case when a named argument
// doesn't match any parameter name in a templated function
// Similar to the error generated in mtype.d's resolveNamedArgs
error(instLoc, "no parameter named `%s`", fname.toChars());
argi = DEFAULT_ARGI;
}

Expand Down
15 changes: 15 additions & 0 deletions compiler/test/fail_compilation/template_named_args_test.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
TEST_OUTPUT:
---
fail_compilation/template_named_args_test.d(14): Error: no parameter named `x`
fail_compilation/template_named_args_test.d(14): Error: template `gun` is not callable using argument types `!()(int)`
fail_compilation/template_named_args_test.d(10): Candidate is: `gun(T)(T a)`
---
*/

void gun(T)(T a) {}

void main()
{
gun(x: 1); // (no explanation)
}
Loading