digitalmars.D - immutable method not callable using argument types () - doesn't make
- Daniel Donnelly (27/27) Mar 27 2012 I have: [code]
- Daniel Donnelly (5/5) Mar 27 2012 The two solutions are:
- Steven Schveighoffer (15/19) Mar 27 2012 This transfers the constancy from the object to the result. Is that wha...
- bearophile (4/7) Mar 27 2012 Any space for compiler error message improvements here?
- denizzzka (2/7) Oct 09 2012 +1, spent two hours with a similar problem
- Lee Braiden (5/15) Feb 06 2013 +2. I wasted a little time on this too. Not much, but
- Timon Gehr (8/23) Feb 06 2013 I am writing a D compiler front end, and currently the following message...
- Lee Braiden (6/12) Feb 07 2013 Almost, it's definitely better, but what's wrong with:
I have: [code] module A; interface B { public: immutable B dup(); } class A : B { public: this() {} this(in char[] field) { this.field = field.dup; } immutable A dup() { return new A(field); } private: char[] field; } void main() { B f, g; f = new A; g = new A; f = g.dup; } [/code] Compile: dmd A Compile Output: A.d(23): Error: function A.B.dup () immutable is not callable using argument types ()
Mar 27 2012
The two solutions are: inout(A) dup() inout { ... } A dup() const { ... } I'm using the latter. Basically all I need is to copy any object: const, immut-, or mutable.
Mar 27 2012
On Tue, 27 Mar 2012 04:49:57 -0400, Daniel Donnelly <enjoysmath gmail.com> wrote:The two solutions are: inout(A) dup() inout { ... }This transfers the constancy from the object to the result. Is that what you want? For arrays, dup means "return mutable", no matter what constancy it is called on.I'm using the latter. Basically all I need is to copy any object: const, immut-, or mutable.BTW, here is what the compiler is complaining about: immutable B dup(); This is a member function, with the attribute immutable. What this does is specify that the hidden 'this' pointer is immutable. It's equivalent to this: B dup(immutable(B) this); So what the compiler is saying is that you can't call dup with arguments (), you must call it with arguments '() immutable', meaning you must call it on an immutable B, not a mutable B. -Steve
Mar 27 2012
Steven Schveighoffer:So what the compiler is saying is that you can't call dup with arguments (), you must call it with arguments '() immutable', meaning you must call it on an immutable B, not a mutable B.Any space for compiler error message improvements here? Bye, bearophile
Mar 27 2012
On Tuesday, 27 March 2012 at 12:57:18 UTC, bearophile wrote:Steven Schveighoffer:+1, spent two hours with a similar problemSo what the compiler is saying is that you can't call dup with arguments (), you must call it with arguments '() immutable', meaning you must call it on an immutable B, not a mutable B.Any space for compiler error message improvements here?
Oct 09 2012
On Tuesday, 9 October 2012 at 22:47:16 UTC, denizzzka wrote:On Tuesday, 27 March 2012 at 12:57:18 UTC, bearophile wrote:+2. I wasted a little time on this too. Not much, but frustratingly more than necessary. Why someone would write that error message makes SOME sense when explained, but the error message itself is still non-sensical ;)Steven Schveighoffer:+1, spent two hours with a similar problemSo what the compiler is saying is that you can't call dup with arguments (), you must call it with arguments '() immutable', meaning you must call it on an immutable B, not a mutable B.Any space for compiler error message improvements here?
Feb 06 2013
On 02/07/2013 12:13 AM, Lee Braiden wrote:On Tuesday, 9 October 2012 at 22:47:16 UTC, denizzzka wrote:I am writing a D compiler front end, and currently the following message is displayed for the example: A.d:22:9: error: receiver for member function 'dup' is unqualified, but 'immutable' is required f = g.dup; ^~~~~ Is this what you'd want?On Tuesday, 27 March 2012 at 12:57:18 UTC, bearophile wrote:+2. I wasted a little time on this too. Not much, but frustratingly more than necessary. Why someone would write that error message makes SOME sense when explained, but the error message itself is still non-sensical ;)Steven Schveighoffer:+1, spent two hours with a similar problemSo what the compiler is saying is that you can't call dup with arguments (), you must call it with arguments '() immutable', meaning you must call it on an immutable B, not a mutable B.Any space for compiler error message improvements here?
Feb 06 2013
On Thu, 07 Feb 2013 00:31:20 +0100, Timon Gehr wrote:A.d:22:9: error: receiver for member function 'dup' is unqualified, but 'immutable' is required f = g.dup; ^~~~~ Is this what you'd want?Almost, it's definitely better, but what's wrong with: "immutable object method dup cannot be called on mutable object d" ? ;) -- Lee
Feb 07 2013