Bug 19203 – alias this to a bool behaves both inconsistently and incorrectly with static assert
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-08-29T04:11:23Z
Last change time
2018-10-05T11:34:06Z
Assigned to
No Owner
Creator
Nicholas Wilson
Comments
Comment #0 by iamthewilsonator — 2018-08-29T04:11:23Z
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;
}
Comment #1 by iamthewilsonator — 2018-08-29T04:23:32Z
s/isArrayLike/hasPopBack
Comment #2 by github-bugzilla — 2018-10-05T11:34:05Z