struct BoolWithErr { bool b; string error; alias b this; } struct Foo {} template hasPopBack(T) { static if (!is(typeof(T.init.popBack))) enum hasPopBack = BoolWithErr(false, T.stringof~" does not have popBack"); else enum hasPopBack = BoolWithErr(true,""); } int main() { // Fine: auto a = isArrayLike!Foo && isArrayLike!Foo; // false enum b = isArrayLike!Foo && isArrayLike!Foo; // false pragma(msg, typeof(a)); // bool // Fine: // Error: static assert: b is false static assert(b); // Dubious: alias this b should work // Error: expression isArrayLike!(Foo) of type BoolWithErr does not have a boolean value // while evaluating: static assert(isArrayLike!(Foo)) static assert(isArrayLike!Foo); // Bad: typeof the expression is bool // Error: expression isArrayLike!(Foo) && isArrayLike!Foo of type BoolWithErr does not have a boolean value // while evaluating: static assert(isArrayLike!(Foo) && isArrayLike!Foo) static assert(isArrayLike!Foo && isArrayLike!Foo); return 0; }
s/isArrayLike/hasPopBack
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/575458309f4ea897b743081a6a26bd6b7a8eba2e Fix issue 19203 https://github.com/dlang/dmd/commit/0490ffc24ecb0471302781a8923aa7bf249a9079 Merge pull request #8634 from thewilsonator/staticassertaliasthisbool Fix issue 19203 - alias this to a bool behaves both inconsistently and incorrectly with static assert merged-on-behalf-of: Razvan Nitu <RazvanN7@users.noreply.github.com>