Bug 9631 – Error message not using fully qualified name when appropriate.
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-03-02T01:29:14Z
Last change time
2022-09-08T14:21:18Z
Keywords
diagnostic
Assigned to
No Owner
Creator
deadalnix
Comments
Comment #0 by deadalnix — 2013-03-02T01:29:14Z
I'm doing some refactoring in SDC. Doing so, I'm moving this to use a new implementation of Location. I get often message like :
Error: cannot implicitly convert expression (e.location) of type Location to Location
The error message is about me using the new Location when the old is expected or the other way around. But the message itself is kind of cryptic.
DMD should use the fully qualified name in error message when the regular name isn't enough.
Comment #1 by bearophile_hugs — 2013-03-02T05:21:58Z
(In reply to comment #0)
> The error message is about me using the new Location when the old is expected
> or the other way around. But the message itself is kind of cryptic.
I suggest to add here a minimal complete program example.
Comment #2 by andrej.mitrovich — 2013-03-02T08:03:41Z
Test case:
template T1()
{
struct F { }
}
template T2()
{
struct F { }
}
void main()
{
T2!().F x = T1!().F();
}
> Error: cannot implicitly convert expression (F()) of type F to F
Comment #3 by andrej.mitrovich — 2013-03-20T14:30:53Z
*** Issue 9767 has been marked as a duplicate of this issue. ***
Comment #4 by luka8088 — 2013-04-18T12:39:24Z
Test case (from #9949):
// Error: function literal __lambda3 (S!(s) a) is not
// callable using argument types (S!(s))
module program;
struct S (alias T) {
typeof(T) value;
}
void f (alias l = x => 1) (string s) {
l(S!(s).init);
}
void main () {
auto s = "some-string";
f!((S!s a) { return 1; })(s);
}
Comment #5 by andrej.mitrovich — 2013-08-18T11:08:04Z
Here's another example:
test.d:
-----
module test;
import foo;
struct S { }
void main()
{
test(S());
}
-----
-----
module foo;
struct S { }
void test(S s) { }
-----
test.d(9): Error: function foo.test (S s) is not callable using argument types (S)
There used to be another error message here which would say "Cannot implicitly convert type S to S", and *that* error message is the one that should really be fixed, however Walter removed the message. I think it will eventually come back though.
Comment #6 by markisaa — 2014-07-11T00:23:44Z
Was just about to report this myself. Hoping that a reply draws a bit more attention. This became apparent when I accidentally imported std.json instead of the revised/improved version I have locally (and whose changes are in the next dmd release).
Comment #7 by jiki — 2014-07-11T02:49:29Z
To fix this, replace each occurrence of xtype->toChars()
with xtype->toPrettyChars(true).
For instance,
Expression *BinExp::incompatibleTypes() in dmd/src/expression.c:
error("incompatible types for ((%s) %s (%s)): '%s' and '%s'",
e1->toChars(), Token::toChars(thisOp), e2->toChars(),
e1->type->toChars(), e2->type->toChars()); // <--- PATCH HERE, 2 of 2
As Comment 0,
Expression *implicitCastTo(Expression *e, Scope *sc, Type *t) in dmd/src/cast.c:
e->error("cannot implicitly convert expression (%s) of type %s to %s",
e->toChars(), e->type->Chars(), t->toChars()); // <--- PATCH HERE, last 2 of 3
# But it isn't enough checked. :P
Maybe we could change this to trivial?
I belive it is not hard to fix this. I can do it my self if there is no one else willing to do.
Comment #10 by nick — 2017-02-15T15:04:29Z
*** Issue 15077 has been marked as a duplicate of this issue. ***
Comment #11 by arbmind — 2017-05-08T11:30:14Z
I tried to tackle this issue at DConf Hackathon.
The issue is not totally trivial. Fully qualifying all types in error messages leads to unreadable error messages.
Imagine a function with 5 arguments, where each argument is fully qualified.
The good solution would be to detect that the error message is ambiguous and only then fall back to fully qualified types.
To do this each error has to be inspected separately. Some are more complicated, as types of expressions and arguments are generated independently right now.
I suggest to split this issue and create issues for all the situations types are reported to be ambiguous and tackle them one by one. Solving them all at once is quite an endeavor.
Comment #12 by destructionator — 2017-05-08T13:03:59Z
> Fully qualifying all types in error messages leads to unreadable error messages.
I would say if the compiler ever sees `if(t1.toChars == t2.toChars) print toPrettyChars instead`.
But there's another option too.... just output the unreadable error messages on a compiler switch and let external programs like IDEs filter them.
The switch could be `-v`, though I still actually really want to see XML error messages, they could list soooooo much info for ides or external filters.
*** Issue 16610 has been marked as a duplicate of this issue. ***
Comment #19 by nick — 2018-01-02T17:06:40Z
(In reply to Andrej Mitrovic from comment #5)
> test.d(9): Error: function foo.test (S s) is not callable using argument
> types (S)
https://github.com/dlang/dmd/pull/7554
Comment #20 by dlang-bot — 2021-04-01T18:40:01Z
@ibuclaw created dlang/dmd pull request #12339 "[dmd-cxx] Backport fixes and trivial features from upstream dmd" mentioning this issue:
- [dmd-cxx] Issue 9631 - Error message not using fully qualified name
https://github.com/dlang/dmd/pull/12339
Comment #21 by dlang-bot — 2021-04-02T05:45:17Z
dlang/dmd pull request #12339 "[dmd-cxx] Backport fixes and trivial features from upstream dmd" was merged into dmd-cxx:
- 75f99eef83805a4da1bb4b68d1c3f48e8b18b93b by Nick Treleaven:
[dmd-cxx] Issue 9631 - Error message not using fully qualified name
https://github.com/dlang/dmd/pull/12339