www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Is this a compiler bug, or a breaking fix/enhancement?

reply "estew" <estewh gmail.com> writes:
Hi All,

I updated to dmd 2.063 today and all has been going smoothly 
until I decided to try out msgpack.d. I got an error compiling 
the msgpack.d unittest, so out of interest I decided to check 
this using dmd2.062 and it compiled and ran fine.

I admit I don't really understand whether the code should work or 
if it is broken and dmd 2.063 now correctly issues an error. To 
my untrained-D-eye the code looks OK, so any advice would be 
appreciated.


ERROR:
---
msgpack.d(3215): Error: cannot resolve type for value.as!(E).

EXAMPLE:
---
import std.stdio;
import std.traits;

enum E : int {F = -20}
struct S {
     int val;
      trusted  property T as(T)()
         if(is(Unqual!T == int) && !is(Unqual!T == enum))
     {
         return cast(T)(val);
     }
      trusted  property T as(T)()
         if(is(Unqual!T == enum))
     {
         return cast(T)as!(OriginalType!T);
     }
}

void main() {
     S val = S(-20);
     assert(val.as!int == -20);
     assert(val.as!E == E.F); // val.as!E causes a compile time 
error.
}
---


Thanks,
Stewart
May 28 2013
next sibling parent "estew" <estewh gmail.com> writes:
Here's a link to the msgpack.d source:
https://github.com/msgpack/msgpack-d/blob/master/src/msgpack.d

And the error is on line 3211, not 3215 as mentioned in the 
previous post.

Thanks,
Stewart
May 28 2013
prev sibling parent reply "Kenji Hara" <k.hara.pg gmail.com> writes:
On Wednesday, 29 May 2013 at 04:44:16 UTC, estew wrote:
 Hi All,

 I updated to dmd 2.063 today and all has been going smoothly 
 until I decided to try out msgpack.d. I got an error compiling 
 the msgpack.d unittest, so out of interest I decided to check 
 this using dmd2.062 and it compiled and ran fine.

 I admit I don't really understand whether the code should work 
 or if it is broken and dmd 2.063 now correctly issues an error. 
 To my untrained-D-eye the code looks OK, so any advice would be 
 appreciated.


 ERROR:
 ---
 msgpack.d(3215): Error: cannot resolve type for value.as!(E).

 EXAMPLE:
 ---
 import std.stdio;
 import std.traits;

 enum E : int {F = -20}
 struct S {
     int val;
      trusted  property T as(T)()
         if(is(Unqual!T == int) && !is(Unqual!T == enum))
     {
         return cast(T)(val);
     }
      trusted  property T as(T)()
         if(is(Unqual!T == enum))
     {
         return cast(T)as!(OriginalType!T);
     }
 }

 void main() {
     S val = S(-20);
     assert(val.as!int == -20);
     assert(val.as!E == E.F); // val.as!E causes a compile time 
 error.
 }
 ---
This is a compiler regression in 2.063 release. http://d.puremagic.com/issues/show_bug.cgi?id=10197 Kenji Hara
May 28 2013
parent "estew" <estewh gmail.com> writes:
 This is a compiler regression in 2.063 release.
 http://d.puremagic.com/issues/show_bug.cgi?id=10197

 Kenji Hara
Thanks for looking into it. Stewart
May 29 2013