Bug 15366 – Enum typed as bool behaves as bool even when cast
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-11-20T05:16:34Z
Last change time
2020-03-21T03:56:35Z
Keywords
pull, rejects-valid
Assigned to
No Owner
Creator
Lionello Lunesu
Comments
Comment #0 by lio+bugzilla — 2015-11-20T05:16:34Z
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/...
Comment #1 by b2.temp — 2015-11-20T21:09:59Z
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.
Comment #2 by lio+bugzilla — 2015-11-21T11:14:33Z
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.