Bug 8549 – Bad error message with const methods

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2012-08-15T06:07:00Z
Last change time
2012-10-21T14:10:56Z
Keywords
diagnostic
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2012-08-15T06:07:31Z
This needs a much better error message: struct Foo { int[] opSlice() { return [0]; } } struct Bar { Foo spam; const(Foo) bar() const { return spam; } } void main() { Bar().bar()[]; } DMD 2.061alpha gives: test.d(11): Error: function test.Foo.opSlice () is not callable using argument types ()
Comment #1 by andrej.mitrovich — 2012-10-19T20:57:41Z
Issue6707 covers this, the error message is now: test.d(11): Error: function test.Foo.opSlice () is not callable using argument types () const *** This issue has been marked as a duplicate of issue 6707 ***
Comment #2 by bearophile_hugs — 2012-10-19T21:36:07Z
(In reply to comment #1) > Issue6707 covers this, the error message is now: I agree with closing this as dupe. But I think adding "const" at the end is not nearly enough to make the error message clear.
Comment #3 by andrej.mitrovich — 2012-10-19T21:40:56Z
(In reply to comment #2) > (In reply to comment #1) > > Issue6707 covers this, the error message is now: > > I agree with closing this as dupe. > > But I think adding "const" at the end is not nearly enough to make the error > message clear. I would take a bigger pull to fix this since there's a lot of code duplication in DMD. Personally I would change the message to: Error: function test.Foo.opSlice () is not callable using const(this) What do you think?
Comment #4 by andrej.mitrovich — 2012-10-19T21:41:21Z
(In reply to comment #3) > I would take *It* would take.
Comment #5 by bearophile_hugs — 2012-10-20T22:42:12Z
(In reply to comment #3) > I would take a bigger pull to fix this since there's a lot of code duplication > in DMD. Personally I would change the message to: > > Error: function test.Foo.opSlice () is not callable using const(this) > > What do you think? Do you want me to reopen this bug report? Maybe an error message that tells what to do is better (not complete error message): test.d(11): Error: function test.Foo.opSlice() needs to be const to [...]
Comment #6 by bearophile_hugs — 2012-10-21T14:10:56Z
(In reply to comment #5) > Do you want me to reopen this bug report? I have reopened Issue 6707 instead.