Consider this code:
----
struct VecN(T, const uint Dim) {
        /**
         * Stores the vector values.
         */
        T[Dim] values = 0;
        
        /// Alias
        alias values this;
        
        /**
         * CTor
         */
        this(float[Dim] values) {
                this.values = values;
        }
        
        /**
         * opDispatch for x, y, z, w, u, v components
         */
        @property
        T opDispatch(string str)() const pure nothrow {
                //writeln(str); // [1]
                static if (str[0] == 'x')
                        return this.values[0];
                else static if (str[0] == 'y')
                        return this.values[1];
                else static if (str[0] == 'z')
                        return this.values[2];
                else static if (str[0] == 'w')
                        return this.values[3];
                else static if (str[0] == 'u')
                        return this.values[4];
                else static if (str[0] == 'v')
                        return this.values[5];
                else
                        return 0;
        }
}

alias vec2f = VecN!(float, 2);

void main() {
        vec2f[] arr;
        arr ~= vec2f([1, 2]);
        arr ~= vec2f([3, 4]);
        
        import std.stdio;
        writefln("ptr = %x", arr.ptr);
        
}
----

It will fail with:
----
object.Exception@/opt/compilers/dmd2/include/std/format.d(2245): Incorrect format specifier for range: %x
----

But if you comment out [1] it works as expected.

I'm sure it is a bug, but I've no idea how to name it.

Reply via email to