Bug 8477 – [2.060 beta] Strange error calling member func from overridden Exception::toString()

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-07-30T15:35:00Z
Last change time
2012-07-31T01:23:51Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
bus_dbugzilla

Comments

Comment #0 by bus_dbugzilla — 2012-07-30T15:35:04Z
class Foo : Exception { this() { super(""); } int line() { return 0; } override string toString() { line(); return ""; } } Worked on 2.059. On 2.060 beta: test.d(12): Error: function test.Foo.line () is not callable using argument types () const Problem goes away if Foo is *not* derived from Exception.
Comment #1 by dmitry.olsh — 2012-07-30T15:41:59Z
That means Exception has its toString defined as const thus your override also must be const (and implicitly supposed to be). Then it tries to call line and dies. Marking lines as const fixes issue. So it's either invalid report or request for better diagnostics.
Comment #2 by andrej.mitrovich — 2012-07-30T15:49:37Z
(In reply to comment #1) > So it's either invalid report or request for better diagnostics. Your second point is implicit as the numerous complaints show. But toString needs to be implemented with some consistency in Phobos.. Object.toString isn't const, but Throwable.toString is. What's it gonna be?
Comment #3 by issues.dlang — 2012-07-30T17:22:22Z
> But toString needs to be implemented with some consistency in Phobos.. Object.toString isn't const, but Throwable.toString is. What's it gonna be? We're going to move to a model where Object doesn't even _have_ toString on it. So, in the long run, the constancy of Object's toString is irrelevant, and since whether a particular type should have a const toString or not depends on the type and what it's doing, it's ultimately _not_ a question of consistency. I'd expect Throwable and its ilk to have a const toString in the long run. Whether it should be const right now or not, I don't know, since the issue with Object and its various functions is still being sorted out.
Comment #4 by k.hara.pg — 2012-07-30T17:27:36Z
(In reply to comment #2) > (In reply to comment #1) > > So it's either invalid report or request for better diagnostics. > > Your second point is implicit as the numerous complaints show. But toString > needs to be implemented with some consistency in Phobos.. Object.toString isn't > const, but Throwable.toString is. What's it gonna be? It's my mistake. I had reverted const qualifer of Object member functions, but forgotten about Throwable's.
Comment #5 by k.hara.pg — 2012-07-30T18:11:27Z
Comment #6 by github-bugzilla — 2012-07-30T18:32:40Z
Commits pushed to master at https://github.com/D-Programming-Language/druntime https://github.com/D-Programming-Language/druntime/commit/6654dcfbaa23c1b64362c739914b8ba9bb098f05 fix Issue 8477 - [2.060 beta] Strange error calling member func from overridden Exception::toString() Revert const qualifier of Throwable.toString https://github.com/D-Programming-Language/druntime/commit/7ff4fb1e37e00caa7187b39bda403377d888400d Merge pull request #284 from 9rnsr/rev_const Issue 8477 - [2.060 beta] Strange error calling member func from overridden Exception::toString()
Comment #7 by doob — 2012-07-31T01:14:25Z
> We're going to move to a model where Object doesn't even _have_ toString on it. Has there been some kind of official agreement on this? I followed the discussion and to me it looked more like it was going to be possible to have both const and non-const versions of the methods in Object. Is this only your opinion, were there a private discussion or have I just missed it? This is a big change and I really think these decisions need to be properly announced.
Comment #8 by issues.dlang — 2012-07-31T01:23:51Z