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
16 changes: 12 additions & 4 deletions compiler/src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -6723,7 +6723,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
return setError();
}

void errorHelper(const(char)* failMessage) scope
void errorHelper(const(char)* failMessage, Loc argLoc = Loc.initial) scope
{
OutBuffer buf;
buf.writeByte('(');
Expand All @@ -6736,7 +6736,11 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
.error(exp.loc, "%s `%s` is not callable using argument types `%s`",
p, exp.e1.toErrMsg(), buf.peekChars());
if (failMessage)
errorSupplemental(exp.loc, "%s", failMessage);
{
// Use the argument's location if provided, otherwise use the function call location
Loc errorLoc = argLoc != Loc.initial ? argLoc : exp.loc;
errorSupplemental(errorLoc, "%s", failMessage);
}
}

if (callMatch(exp.f, tf, null, exp.argumentList, 0, &errorHelper, sc) == MATCH.nomatch)
Expand Down Expand Up @@ -6799,7 +6803,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
exp.f = exp.f.toAliasFunc();
TypeFunction tf = cast(TypeFunction)exp.f.type;

void errorHelper2(const(char)* failMessage) scope
void errorHelper2(const(char)* failMessage, Loc argLoc = Loc.initial) scope
{
OutBuffer buf;
buf.writeByte('(');
Expand All @@ -6817,7 +6821,11 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
.error(exp.loc, "%s `%s` is not callable using argument types `%s`",
exp.f.kind(), exp.f.toErrMsg(), buf.peekChars());
if (failMessage)
errorSupplemental(exp.loc, "%s", failMessage);
{
// Use the argument's location if provided, otherwise use the function call location
Loc errorLoc = argLoc != Loc.initial ? argLoc : exp.loc;
errorSupplemental(errorLoc, "%s", failMessage);
}
.errorSupplemental(exp.f.loc, "`%s%s` declared here", exp.f.toPrettyChars(), parametersTypeToChars(tf.parameterList));
exp.f = null;
}
Expand Down
12 changes: 8 additions & 4 deletions compiler/src/dmd/funcsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -1837,12 +1837,14 @@ FuncDeclaration resolveFuncCall(Loc loc, Scope* sc, Dsymbol s,
}

bool calledHelper;
void errorHelper(const(char)* failMessage) scope
void errorHelper(const(char)* failMessage, Loc argLoc = Loc.initial) scope
{
.error(loc, "%s `%s%s%s` is not callable using argument types `%s`",
fd.kind(), fd.toPrettyChars(), parametersTypeToChars(tf.parameterList),
tf.modToChars(), fargsBuf.peekChars());
errorSupplemental(loc, failMessage);
// Use the argument's location if provided, otherwise use the function call location
Loc errorLoc = argLoc != Loc.initial ? argLoc : loc;
errorSupplemental(errorLoc, failMessage);
calledHelper = true;
}

Expand Down Expand Up @@ -1910,9 +1912,11 @@ FuncDeclaration resolveFuncCall(Loc loc, Scope* sc, Dsymbol s,
}
}

void errorHelper2(const(char)* failMessage) scope
void errorHelper2(const(char)* failMessage, Loc argLoc = Loc.initial) scope
{
errorSupplemental(loc, failMessage);
// Use the argument's location if provided, otherwise use the function call location
Loc errorLoc = argLoc != Loc.initial ? argLoc : loc;
errorSupplemental(errorLoc, failMessage);
}

functionResolve(m, orig_s, loc, sc, tiargs, tthis, argumentList, &errorHelper2);
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/templatesem.d
Original file line number Diff line number Diff line change
Expand Up @@ -1886,7 +1886,7 @@ extern (D) RootObject declareParameter(TemplateDeclaration td, Scope* sc, Templa
* errorHelper = delegate to send error message to if not null
*/
void functionResolve(ref MatchAccumulator m, Dsymbol dstart, Loc loc, Scope* sc, Objects* tiargs,
Type tthis, ArgumentList argumentList, void delegate(const(char)*) scope errorHelper = null)
Type tthis, ArgumentList argumentList, void delegate(const(char)*, Loc = Loc.initial) scope errorHelper = null)
{
version (none)
{
Expand Down
7 changes: 6 additions & 1 deletion compiler/src/dmd/typesem.d
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ extern (D) bool checkComplexTransition(Type type, Loc loc, Scope* sc)
* MATCHxxxx
*/
extern (D) MATCH callMatch(FuncDeclaration fd, TypeFunction tf, Type tthis, ArgumentList argumentList,
int flag = 0, void delegate(const(char)*) scope errorHelper = null, Scope* sc = null)
int flag = 0, void delegate(const(char)*, Loc = Loc.initial) scope errorHelper = null, Scope* sc = null)
{
//printf("callMatch() fd: %s, tf: %s\n", fd ? fd.ident.toChars() : "null", toChars(tf));
MATCH match = MATCH.exact; // assume exact match
Expand Down Expand Up @@ -872,7 +872,12 @@ extern (D) MATCH callMatch(FuncDeclaration fd, TypeFunction tf, Type tthis, Argu
u + 1, parameterToChars(p, tf, false));
// If an error happened previously, `pMessage` was already filled
else if (buf.length == 0)
{
buf.writestring(tf.getParamError(args[u], p));
// Use the argument's location for the error message instead of the function call location
errorHelper(buf.peekChars(), args[u].loc);
return MATCH.nomatch;
}

errorHelper(buf.peekChars());
}
Expand Down
19 changes: 19 additions & 0 deletions compiler/test/fail_compilation/fix21167.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
TEST_OUTPUT:
---
fail_compilation/fix21167.d(13): Error: function `f` is not callable using argument types `(int, string, int)`
fail_compilation/fix21167.d(15): cannot pass argument `"foo"` of type `string` to parameter `int __param_1`
fail_compilation/fix21167.d(9): `fix21167.f(int __param_0, int __param_1, int __param_2)` declared here
---
*/
void f(int, int, int){}

void main()
{
f(
1,
"foo",
3
);

}
Loading