Skip to content

Commit 064547e

Browse files
committed
Added sol
1 parent c4d45a1 commit 064547e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

compiler/src/dmd/templatesem.d

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,10 @@ extern (D) MATCHpair deduceFunctionTemplateMatch(TemplateDeclaration td, Templat
973973
}
974974
if (fname && !foundName)
975975
{
976+
// This is where we need to handle the error case when a named argument
977+
// doesn't match any parameter name in a templated function
978+
// Similar to the error generated in mtype.d's resolveNamedArgs
979+
error(instLoc, "no parameter named `%s`", fname.toChars());
976980
argi = DEFAULT_ARGI;
977981
}
978982

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
TEST_OUTPUT:
3+
---
4+
fail_compilation/template_named_args_test.d(14): Error: no parameter named `x`
5+
fail_compilation/template_named_args_test.d(14): Error: template `gun` is not callable using argument types `!()(int)`
6+
fail_compilation/template_named_args_test.d(10): Candidate is: `gun(T)(T a)`
7+
---
8+
*/
9+
10+
void gun(T)(T a) {}
11+
12+
void main()
13+
{
14+
gun(x: 1); // (no explanation)
15+
}

0 commit comments

Comments
 (0)