Skip to content

Commit

Permalink
Fix Issue 17518 - [Reg 2.063] confusing error message with inout cons…
Browse files Browse the repository at this point in the history
…tructor/ctor
  • Loading branch information
RazvanN7 committed Dec 18, 2018
1 parent 5da3f20 commit 3d9550c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/dmd/func.d
Original file line number Diff line number Diff line change
Expand Up @@ -2746,15 +2746,27 @@ FuncDeclaration resolveFuncCall(const ref Loc loc, Scope* sc, Dsymbol s,
}
else
{
auto fullFdPretty = fd.toPrettyChars();
.error(loc, "%smethod `%s` is not callable using a %sobject",
funcBuf.peekString(), fullFdPretty,
thisBuf.peekString());

if (mismatches.isNotShared)
.errorSupplemental(loc, "Consider adding `shared` to %s", fullFdPretty);
else if (mismatches.isMutable)
.errorSupplemental(loc, "Consider adding `const` or `inout` to %s", fullFdPretty);
const(char)* failMessage;
functionResolve(&m, orig_s, loc, sc, tiargs, tthis, fargs, &failMessage);
if (failMessage)
{
.error(loc, "%s `%s%s%s` is not callable using argument types `%s`",
fd.kind(), fd.toPrettyChars(), parametersTypeToChars(tf.parameterList),
tf.modToChars(), fargsBuf.peekString());
errorSupplemental(loc, failMessage);
}
else
{
auto fullFdPretty = fd.toPrettyChars();
.error(loc, "%smethod `%s` is not callable using a %sobject",
funcBuf.peekString(), fullFdPretty,
thisBuf.peekString());

if (mismatches.isNotShared)
.errorSupplemental(loc, "Consider adding `shared` to %s", fullFdPretty);
else if (mismatches.isMutable)
.errorSupplemental(loc, "Consider adding `const` or `inout` to %s", fullFdPretty);
}
}
}
else
Expand Down
22 changes: 22 additions & 0 deletions test/fail_compilation/fail17518.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail17518.d(21): Error: constructor `fail17518.S.this(inout(Correct) _param_0) inout` is not callable using argument types `(Wrong)`
fail_compilation/fail17518.d(21): cannot pass argument `Wrong()` of type `Wrong` to parameter `inout(Correct) _param_0`
---
*/

struct S
{
this(inout Correct) inout
{
}
}

struct Correct {}
struct Wrong {}

S bug()
{
return S(Wrong());
}

0 comments on commit 3d9550c

Please sign in to comment.