[Issue 22775] The __traits does not see the scope attribute

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Feb 17 06:43:02 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=22775

--- Comment #3 from Walter Bright <bugzilla at digitalmars.com> ---
The attached example:
--------------------------
import std.traits;
import std.meta;
struct S {
    int x;
}

@safe
interface I {
    int func(ref scope S s) @nogc;
}

@safe
class C : I {
    int func(ref S s) {
        return 2*s.x;
    }
}

@safe
class Cscope : I {
    int func(ref scope S s) {
        return 2*s.x;
    }
}

@safe
class Cconst : I {
    int func(ref const S s) {
        return 2*s.x;
    }
}

@safe
struct ST {
    int func(ref S s) {
        return 2*s.x;
    }
}

@safe
struct STscope {
    int func(ref scope S s) {
        return 2*s.x;
    }
}

@safe
struct STconst {
    int func(ref const S s) {
        return 2*s.x;
    }
}

alias getMemberType(alias O, string name)=typeof(__traits(getMember, O, name));

static unittest {
    pragma(msg, I, " : ", getMemberType!(I, "func"));
    pragma(msg, C, " : ", getMemberType!(C, "func"));
    pragma(msg, Cscope, " : ", getMemberType!(Cscope, "func"));
    pragma(msg, Cconst, " : ", getMemberType!(Cconst, "func"));
    pragma(msg, getMemberType!(Cscope, "func").stringof);
    static assert(getMemberType!(Cscope, "func").stringof ==
        q{@nogc @safe int(ref scope S s)});
}

static unittest {
    pragma(msg, ST, " : ", getMemberType!(ST, "func"));
    pragma(msg, STscope, " : ", getMemberType!(STscope, "func"));
    pragma(msg, STconst, " : ", getMemberType!(STconst, "func"));
    static assert(getMemberType!(STscope, "func").stringof ==
        q{@safe int(ref scope S s)});
}

--


More information about the Digitalmars-d-bugs mailing list