enum Enum : bool { A, B }; struct I{ void func(Enum e); void func2(Enum a, Enum b) {func(cast(Enum)(a&&b));} //line 4 } test.d(4): Error: function test.I.func (Enum e) is not callable using argument types (bool) There are many changes to this code that will get rid of the error: * placing any one, or both, of the functions on global scope * using bitwise & instead of logic && * removing the type from the enum, or typing as byte/int/...
That's funny because this compiles: --- enum Enum : bool { A, B } struct I{ void func(Enum e){} void func4(Enum a, Enum b) { (&func)(cast(Enum)(a && b)); } void func3(Enum a, Enum b) { Enum aa = cast(Enum)(a && b); func(aa); } } --- the error message seems totally meaningless when you consider func4. func3 suggests that the real problem is that it needs a lvalue.
Adding an explicit "this." fixed the issue: enum Enum : bool { A, B }; struct I{ void func(Enum e); void func2(Enum a, Enum b) {this.func(cast(Enum)(a&&b));} } Something happens when the compiler adds the "this" in your behalf. The resolution changes.
https://github.com/D-Programming-Language/dmd/pull/5279
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/67a21a9ec222e63ad5bab445662de9114878bc90 fix Issue 15366 - Enum typed as bool behaves as bool even when cast From a CastExp 'a && b', its `semantic` returns an `AndAndExp` with the 'Enum' type. But if its `semantic` will be called once more, it will repaint its `type` to 'bool'. Same problem exists in `OrOrExp`. https://github.com/D-Programming-Language/dmd/commit/913ffbe000e99e3a2aa6caaea9994a103503d6ac Merge pull request #5279 from 9rnsr/fix15366 Issue 15366 - Enum typed as bool behaves as bool even when cast
Commits pushed to stable at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/67a21a9ec222e63ad5bab445662de9114878bc90 fix Issue 15366 - Enum typed as bool behaves as bool even when cast https://github.com/D-Programming-Language/dmd/commit/913ffbe000e99e3a2aa6caaea9994a103503d6ac Merge pull request #5279 from 9rnsr/fix15366