Le 30/05/2012 10:58, Tommi a écrit :
struct ValueImpl
{
static immutable(int) getValue()
{
return 42;
}
}

struct ValueUser
{
ValueImpl m_valueImpl;
alias m_valueImpl this;
}

void main(string[] args)
{
static assert(ValueImpl.getValue() == 42);
static assert(ValueUser.getValue() == 42); // (1)
}

(1) Doesn't compile. Error: variable m_valueImpl cannot be read at
compile time

To use alias this for composition, it would be nice if the compile-time
evaluable members of the aliased object would remain compile-time
evaluable even when used through an alias. Is the current behavior
defined by the language or is it due to the compiler (DMD) implementation?

m_valueImpl isn't static and ValueUser not instantiated. I wouldn't expect this to compile at all, CTFE or not.

Reply via email to