Bug 1730 – Bogus error message calling a non-const struct method on a const struct reference

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2007-12-13T23:52:00Z
Last change time
2015-06-09T01:14:23Z
Keywords
diagnostic, pull
Assigned to
andrej.mitrovich
Creator
davidl

Comments

Comment #0 by davidl — 2007-12-13T23:52:08Z
struct mystruct{ invariant(char)[] toChars() { return "asdf"; } } void func(in mystruct s) { invariant(char)[] k=s.toChars; } testconst.d(9): function testconst.mystruct.toChars () does not match parameter types () testconst.d(9): Error: s.toChars can only be called on a mutable object, not const(mystruct)
Comment #1 by caron800 — 2007-12-14T01:10:32Z
On 12/14/07, [email protected] <[email protected]> wrote: > struct mystruct{ > invariant(char)[] toChars() > { > return "asdf"; > } > } > void func(in mystruct s) > { > invariant(char)[] k=s.toChars; > } That's correct behaviour, surely? Change the function definition to const invariant(char)[] toChars() { return "asdf"; } and the problem should go away. toChars() as written is incorrectly declared. It does not modify this, therefore it should be declared const. That said, I don't understant how s got to be const in the first place! Does "in" make things const?
Comment #2 by davidl — 2007-12-15T07:40:06Z
But at least the first error message is confusing.
Comment #3 by smjg — 2009-11-20T11:10:48Z
Probably part of the same bug: ---------- class Class { void fn1() const { fn2(); } void fn2() {} } ---------- const_call.d(3): Error: function const_call.Class.fn2 () is not callable using argument types () const ---------- This may make sense at the internal level, as trying to convert the 'this' argument implicitly from const(Class) to Class. But as a user error message, it's confusing.
Comment #4 by gim913 — 2010-03-13T07:25:52Z
I has similar problem with: struct Foo { bool boo() { return false; } int foo () const { assert (boo); return 66; } } this message is totally misleading
Comment #5 by andrej.mitrovich — 2012-12-23T13:45:29Z
*** Issue 3642 has been marked as a duplicate of this issue. ***
Comment #6 by andrej.mitrovich — 2012-12-23T13:45:34Z
*** Issue 4497 has been marked as a duplicate of this issue. ***
Comment #7 by andrej.mitrovich — 2012-12-23T13:47:23Z
There's a ton of duplicate reports on this diagnostic. We better come up with a better error message than what we have now because there's a lot of complaints.
Comment #8 by andrej.mitrovich — 2012-12-25T06:31:46Z
Comment #9 by andrej.mitrovich — 2012-12-27T17:43:17Z
*** Issue 6707 has been marked as a duplicate of this issue. ***
Comment #10 by andrej.mitrovich — 2012-12-27T17:50:19Z
*** Issue 6981 has been marked as a duplicate of this issue. ***
Comment #11 by github-bugzilla — 2013-01-02T23:18:49Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/80d12f303c6184c9423a08b6d984db469ec27927 Fix Issue 1730 - Error message on 'this' reference modifier mismatch when calling methods is uninformative https://github.com/D-Programming-Language/dmd/commit/99e93a62383a627497d7eafbee772b99329cb70f Merge pull request #1407 from AndrejMitrovic/Fix1730 Issue 1730 - Error message on 'this' reference modifier mismatch is uninformative