Skip to content

Commit

Permalink
Fully qualify parameter instead of showing type separately; fix ddoc
Browse files Browse the repository at this point in the history
  • Loading branch information
ntrel committed Jan 2, 2018
1 parent fb1e928 commit 02b244b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
17 changes: 9 additions & 8 deletions src/dmd/func.d
Expand Up @@ -3634,13 +3634,14 @@ void showArgMismatch(Loc loc, Expressions* fargs, TypeFunction tf, size_t failIn
auto arg = (*fargs)[failIndex];
auto par = (*tf.parameters)[failIndex];
const rv = (!arg.isLvalue() && par.storageClass & (STCref | STCout)) ? "rvalue " : "";
const pc = parameterToChars(par, tf.varargs);
const ts = toAutoQualChars(arg.type, par.type);
auto msg = "cannot pass %sargument `%s` of type `%s` to parameter `%s`";
// don't print parameter type if it's already in the parameter string
if (strcmp(par.type.toChars(), ts[1]) != 0)
msg ~= " of type `%s`\0";
errorSupplemental(loc, msg.ptr,
rv.ptr, arg.toChars(), ts[0], pc, ts[1]);

// disambiguate when toChars() is the same
auto at = arg.type.toChars();
bool qual = !arg.type.equals(par.type) && strcmp(at, par.type.toChars()) == 0;
if (qual)
at = arg.type.toPrettyChars(true);

errorSupplemental(loc, "cannot pass %sargument `%s` of type `%s` to parameter `%s`",
rv.ptr, arg.toChars(), at, parameterToChars(par, tf.varargs, qual));
}
}
12 changes: 7 additions & 5 deletions src/dmd/hdrgen.d
Expand Up @@ -3428,8 +3428,8 @@ extern (C++) void arrayObjectsToBuffer(OutBuffer* buf, Objects* objects)
/** Pretty print function parameters.
* Params:
* parameters = parameters to print, such as TypeFunction.parameters.
* varargs = Kind of varargs, see TypeFunction.varargs.
* Returns: NT string representing parameters. */
* varargs = kind of varargs, see TypeFunction.varargs.
* Returns: Null-terminated string representing parameters. */
extern (C++) const(char)* parametersTypeToChars(Parameters* parameters, int varargs)
{
OutBuffer buf;
Expand All @@ -3442,12 +3442,14 @@ extern (C++) const(char)* parametersTypeToChars(Parameters* parameters, int vara
/** Pretty print function parameters.
* Params:
* parameter = parameter to print.
* varargs = Kind of varargs, see TypeFunction.varargs.
* Returns: NT string representing parameter. */
extern (C++) const(char)* parameterToChars(Parameter parameter, int varargs)
* varargs = kind of varargs, see TypeFunction.varargs.
* fullQual = whether to fully qualify types.
* Returns: Null-terminated string representing parameters. */
extern (C++) const(char)* parameterToChars(Parameter parameter, int varargs, bool fullQual)
{
OutBuffer buf;
HdrGenState hgs;
hgs.fullQual = fullQual;
scope PrettyPrintVisitor v = new PrettyPrintVisitor(&buf, &hgs);

parameter.accept(v);
Expand Down
8 changes: 4 additions & 4 deletions test/fail_compilation/bug9631.d
Expand Up @@ -63,11 +63,11 @@ void test3()
TEST_OUTPUT:
---
fail_compilation/bug9631.d(79): Error: function bug9631.arg.f `(int i, S s)` is not callable using argument types `(int, S)`
fail_compilation/bug9631.d(79): cannot pass argument `y` of type `bug9631.tem!().S` to parameter `S s` of type `bug9631.S`
fail_compilation/bug9631.d(79): cannot pass argument `y` of type `bug9631.tem!().S` to parameter `bug9631.S s`
fail_compilation/bug9631.d(80): Error: function literal `__lambda2(S s)` is not callable using argument types `(S)`
fail_compilation/bug9631.d(80): cannot pass argument `x` of type `bug9631.S` to parameter `S s` of type `bug9631.tem!().S`
fail_compilation/bug9631.d(80): cannot pass argument `x` of type `bug9631.S` to parameter `bug9631.tem!().S s`
fail_compilation/bug9631.d(86): Error: constructor bug9631.arg.A.this `(S _param_0)` is not callable using argument types `(S)`
fail_compilation/bug9631.d(86): cannot pass argument `S(0)` of type `bug9631.tem!().S` to parameter `S _param_0` of type `bug9631.S`
fail_compilation/bug9631.d(86): cannot pass argument `S(0)` of type `bug9631.tem!().S` to parameter `bug9631.S _param_0`
---
*/
void arg()
Expand All @@ -90,7 +90,7 @@ void arg()
TEST_OUTPUT:
---
fail_compilation/bug9631.d(106): Error: function bug9631.targ.ft!().ft `(S _param_0)` is not callable using argument types `(S)`
fail_compilation/bug9631.d(106): cannot pass argument `x` of type `bug9631.S` to parameter `S _param_0` of type `bug9631.tem!().S`
fail_compilation/bug9631.d(106): cannot pass argument `x` of type `bug9631.S` to parameter `bug9631.tem!().S _param_0`
fail_compilation/bug9631.d(107): Error: template `bug9631.targ.ft` cannot deduce function from argument types `!()(S)`, candidates are:
fail_compilation/bug9631.d(105): `bug9631.targ.ft()(tem!().S)`
fail_compilation/bug9631.d(109): Error: template `bug9631.targ.ft2` cannot deduce function from argument types `!()(S, int)`, candidates are:
Expand Down

0 comments on commit 02b244b

Please sign in to comment.