Skip to content

Commit

Permalink
Fix Issue 11529 - Unclear error message when rvalue is passed as `ref'
Browse files Browse the repository at this point in the history
Also hide separate parameter type when already shown.
  • Loading branch information
ntrel authored and wilzbach committed Jan 25, 2018
1 parent 48c6b49 commit ff99241
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 32 deletions.
12 changes: 9 additions & 3 deletions src/dmd/func.d
Expand Up @@ -3641,8 +3641,14 @@ void showArgMismatch(Loc loc, Expressions* fargs, TypeFunction tf, size_t failIn
{
auto arg = (*fargs)[failIndex];
auto par = (*tf.parameters)[failIndex];
auto ts = toAutoQualChars(arg.type, par.type);
errorSupplemental(loc, "cannot pass argument `%s` of type `%s` to parameter `%s` (of type `%s`)",
arg.toChars(), ts[0], parameterToChars(par, tf.varargs), ts[1]);
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`";
errorSupplemental(loc, msg.ptr,
rv.ptr, arg.toChars(), ts[0], pc, ts[1]);
}
}
27 changes: 14 additions & 13 deletions test/fail_compilation/bug9631.d
Expand Up @@ -62,20 +62,20 @@ 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 implicitly convert expression `y` of type `bug9631.tem!().S` to `bug9631.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 implicitly convert expression `x` of type `bug9631.S` to `bug9631.tem!().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 implicitly convert expression `S(0)` of type `bug9631.tem!().S` to `bug9631.S`
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(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(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`
---
*/
void arg()
{
S x;
tem!().S y;

void f(int i, S s){};
void f(int i, S s);
f(4, y);
(tem!().S s){}(x);

Expand All @@ -89,12 +89,13 @@ void arg()
/*
TEST_OUTPUT:
---
fail_compilation/bug9631.d(105): Error: function bug9631.targ.ft!().ft (S _param_0) is not callable using argument types (S)
fail_compilation/bug9631.d(105): cannot implicitly convert expression `x` of type `bug9631.S` to `bug9631.tem!().S`
fail_compilation/bug9631.d(106): Error: template bug9631.targ.ft cannot deduce function from argument types !()(S), candidates are:
fail_compilation/bug9631.d(104): bug9631.targ.ft()(tem!().S)
fail_compilation/bug9631.d(108): Error: template bug9631.targ.ft2 cannot deduce function from argument types !()(S, int), candidates are:
fail_compilation/bug9631.d(107): bug9631.targ.ft2(T)(S, T)
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(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:
fail_compilation/bug9631.d(108): `bug9631.targ.ft2(T)(S, T)`
---
*/
void targ()
{
Expand Down
6 changes: 4 additions & 2 deletions test/fail_compilation/diag13082.d
@@ -1,8 +1,10 @@
/*
TEST_OUTPUT:
---
fail_compilation/diag13082.d(22): Error: constructor `diag13082.C.this(int a)` is not callable using argument types `(string)`
fail_compilation/diag13082.d(23): Error: constructor `diag13082.S.this(int a)` is not callable using argument types `(string)`
fail_compilation/diag13082.d(24): Error: constructor `diag13082.C.this(int a)` is not callable using argument types `(string)`
fail_compilation/diag13082.d(24): cannot pass argument `b` of type `string` to parameter `int a`
fail_compilation/diag13082.d(25): Error: constructor `diag13082.S.this(int a)` is not callable using argument types `(string)`
fail_compilation/diag13082.d(25): cannot pass argument `b` of type `string` to parameter `int a`
---
*/

Expand Down
17 changes: 9 additions & 8 deletions test/fail_compilation/diag8101b.d
@@ -1,14 +1,15 @@
/*
TEST_OUTPUT:
---
fail_compilation/diag8101b.d(26): Error: none of the overloads of `foo` are callable using argument types `(double)`, candidates are:
fail_compilation/diag8101b.d(17): `diag8101b.S.foo(int _param_0)`
fail_compilation/diag8101b.d(18): `diag8101b.S.foo(int _param_0, int _param_1)`
fail_compilation/diag8101b.d(28): Error: function `diag8101b.S.bar(int _param_0)` is not callable using argument types `(double)`
fail_compilation/diag8101b.d(31): Error: none of the overloads of `foo` are callable using a `const` object, candidates are:
fail_compilation/diag8101b.d(17): `diag8101b.S.foo(int _param_0)`
fail_compilation/diag8101b.d(18): `diag8101b.S.foo(int _param_0, int _param_1)`
fail_compilation/diag8101b.d(33): Error: mutable method `diag8101b.S.bar` is not callable using a `const` object
fail_compilation/diag8101b.d(27): Error: none of the overloads of `foo` are callable using argument types `(double)`, candidates are:
fail_compilation/diag8101b.d(18): `diag8101b.S.foo(int _param_0)`
fail_compilation/diag8101b.d(19): `diag8101b.S.foo(int _param_0, int _param_1)`
fail_compilation/diag8101b.d(29): Error: function `diag8101b.S.bar(int _param_0)` is not callable using argument types `(double)`
fail_compilation/diag8101b.d(29): cannot pass argument `1.00000` of type `double` to parameter `int _param_0`
fail_compilation/diag8101b.d(32): Error: none of the overloads of `foo` are callable using a `const` object, candidates are:
fail_compilation/diag8101b.d(18): `diag8101b.S.foo(int _param_0)`
fail_compilation/diag8101b.d(19): `diag8101b.S.foo(int _param_0, int _param_1)`
fail_compilation/diag8101b.d(34): Error: mutable method `diag8101b.S.bar` is not callable using a `const` object
---
*/

Expand Down
3 changes: 2 additions & 1 deletion test/fail_compilation/fail263.d
@@ -1,7 +1,8 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail263.d(18): Error: function `fail263.f(byte* p)` is not callable using argument types `(const(byte)*)`
fail_compilation/fail263.d(19): Error: function `fail263.f(byte* p)` is not callable using argument types `(const(byte)*)`
fail_compilation/fail263.d(19): cannot pass argument `cast(const(byte)*)A` of type `const(byte)*` to parameter `byte* p`
---
*/

Expand Down
3 changes: 2 additions & 1 deletion test/fail_compilation/fail322.d
@@ -1,7 +1,8 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail322.d(10): Error: function `fail322.digestToString2(ref char[16] digest)` is not callable using argument types `(string)`
fail_compilation/fail322.d(11): Error: function `fail322.digestToString2(ref char[16] digest)` is not callable using argument types `(string)`
fail_compilation/fail322.d(11): cannot pass rvalue argument `"1234567890123456"` of type `string` to parameter `ref char[16] digest`
---
*/

Expand Down
3 changes: 2 additions & 1 deletion test/fail_compilation/fail53.d
@@ -1,7 +1,8 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail53.d(25): Error: function `object.Object.opEquals(Object o)` is not callable using argument types `(int)`
fail_compilation/fail53.d(26): Error: function `object.Object.opEquals(Object o)` is not callable using argument types `(int)`
fail_compilation/fail53.d(26): cannot pass argument `i` of type `int` to parameter `Object o`
---
*/

Expand Down
3 changes: 2 additions & 1 deletion test/fail_compilation/fail55.d
@@ -1,7 +1,8 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail55.d(22): Error: function `object.Object.opCmp(Object o)` is not callable using argument types `(int)`
fail_compilation/fail55.d(23): Error: function `object.Object.opCmp(Object o)` is not callable using argument types `(int)`
fail_compilation/fail55.d(23): cannot pass argument `0` of type `int` to parameter `Object o`
---
*/

Expand Down
5 changes: 3 additions & 2 deletions test/fail_compilation/ice14923.d
@@ -1,8 +1,9 @@
/*
TEST_OUTPUT:
---
fail_compilation/ice14923.d(21): Error: function `ice14923.parse(C a)` is not callable using argument types `(A)`
fail_compilation/ice14923.d(21): instantiated from here: `bar!((b) => parse(b))`
fail_compilation/ice14923.d(22): Error: function `ice14923.parse(C a)` is not callable using argument types `(A)`
fail_compilation/ice14923.d(22): cannot pass argument `b` of type `ice14923.A` to parameter `C a`
fail_compilation/ice14923.d(22): instantiated from here: bar!((b) => parse(b))
---
*/

Expand Down

0 comments on commit ff99241

Please sign in to comment.