Is this a compiler bug, or a breaking fix/enhancement?

estew estewh at gmail.com
Tue May 28 21:44:14 PDT 2013


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


More information about the Digitalmars-d-learn mailing list