www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Issue with dmd 2.066, alias this, and sort

reply "rcor" <murphyslaw480 gmail.com> writes:
I've tried to express my problem in a mostly minimal example here:
https://gist.github.com/murphyslaw480/d4a5f857a104bcf62de1

The class Point has an alias this to its own property 
'feature()', which returns a reference to a private member. When 
I try to sort a Point[], DMD fails with "mutable method feature 
is not callable on const object". I'm not actually using the 
property 'feature()' or the alias this in the sorting, so it 
seems like it shouldn't interfere. That being said, I'm still 
slightly const-challenged so maybe its an error on my part. 
However, the above example compiles fine with DMD 2.065.0-3.
Aug 27 2014
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
rcor:

 I've tried to express my problem in a mostly minimal example 
 here:
 https://gist.github.com/murphyslaw480/d4a5f857a104bcf62de1

 The class Point has an alias this to its own property 
 'feature()', which returns a reference to a private member. 
 When I try to sort a Point[], DMD fails with "mutable method 
 feature is not callable on const object". I'm not actually 
 using the property 'feature()' or the alias this in the 
 sorting, so it seems like it shouldn't interfere. That being 
 said, I'm still slightly const-challenged so maybe its an error 
 on my part. However, the above example compiles fine with DMD 
 2.065.0-3.
It compiles if you use: property auto feature() const pure nothrow { return _feature; } Otherwise I get strange errors like: ...\dmd2\src\phobos\std\exception.d(986,31): Error: pure function 'std.exception.doesPointTo!(Point, Point, void).doesPointTo' cannot call impure function 'temp.Point.feature' Bye, bearophile
Aug 27 2014
next sibling parent "rcor" <murphyslaw480 gmail.com> writes:
On Wednesday, 27 August 2014 at 21:43:40 UTC, bearophile wrote:
 It compiles if you use:
  property auto feature() const pure nothrow { return _feature; }

 Otherwise I get strange errors like:

 ...\dmd2\src\phobos\std\exception.d(986,31): Error: pure 
 function 'std.exception.doesPointTo!(Point, Point, 
 void).doesPointTo' cannot call impure function 
 'temp.Point.feature'

 Bye,
 bearophile
Thanks bearophile, that does make the gist compile. However, in my own code, I'm getting all sorts of complaints from other modules about mutable methods not being callable on const objects (the alias this surfaces some methods that are mutable). I guess its my own fault for not being diligent about const-correctness, but it seems odd that sort would care about the constness of feature() when it is sorting based on x and y. Do you know if there is a reason for this?
Aug 27 2014
prev sibling parent reply "monarch_dodra" <monarchdodra gmail.com> writes:
On Wednesday, 27 August 2014 at 21:43:40 UTC, bearophile wrote:
 rcor:

 I've tried to express my problem in a mostly minimal example 
 here:
 https://gist.github.com/murphyslaw480/d4a5f857a104bcf62de1

 The class Point has an alias this to its own property 
 'feature()', which returns a reference to a private member. 
 When I try to sort a Point[], DMD fails with "mutable method 
 feature is not callable on const object". I'm not actually 
 using the property 'feature()' or the alias this in the 
 sorting, so it seems like it shouldn't interfere. That being 
 said, I'm still slightly const-challenged so maybe its an 
 error on my part. However, the above example compiles fine 
 with DMD 2.065.0-3.
It compiles if you use: property auto feature() const pure nothrow { return _feature; } Otherwise I get strange errors like: ...\dmd2\src\phobos\std\exception.d(986,31): Error: pure function 'std.exception.doesPointTo!(Point, Point, void).doesPointTo' cannot call impure function 'temp.Point.feature' Bye, bearophile
Seems like a library bug. Unsure if DMD or phobos for this one, but there is definitely a phobos bug to be fixed anyways. I'll investigate both.
Aug 28 2014
parent reply "monarch_dodra" <monarchdodra gmail.com> writes:
On Thursday, 28 August 2014 at 10:38:12 UTC, monarch_dodra wrote:
 On Wednesday, 27 August 2014 at 21:43:40 UTC, bearophile wrote:
 rcor:


 It compiles if you use:
  property auto feature() const pure nothrow { return _feature; 
 }

 Otherwise I get strange errors like:

 ...\dmd2\src\phobos\std\exception.d(986,31): Error: pure 
 function 'std.exception.doesPointTo!(Point, Point, 
 void).doesPointTo' cannot call impure function 
 'temp.Point.feature'

 Bye,
 bearophile
Seems like a library bug. Unsure if DMD or phobos for this one, but there is definitely a phobos bug to be fixed anyways. I'll investigate both.
DMD issue: https://issues.dlang.org/show_bug.cgi?id=13392 Phobos issue: http://forum.dlang.org/thread/uignsankcumgmhwpoead forum.dlang.org#post-uignsankcumgmhwpoead:40forum.dlang.org
Aug 28 2014
parent "monarch_dodra" <monarchdodra gmail.com> writes:
On Thursday, 28 August 2014 at 10:54:47 UTC, monarch_dodra wrote:
 Phobos issue:
 http://forum.dlang.org/thread/uignsankcumgmhwpoead forum.dlang.org#post-uignsankcumgmhwpoead:40forum.dlang.org
https://github.com/D-Programming-Language/phobos/pull/2472
Aug 28 2014