-
-
Notifications
You must be signed in to change notification settings - Fork 662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
abstract @:to conversion is not triggered within boolean operation #6893
Comments
This seems reasonable to me, abstract A(String) from String to String {
@:op(A && B) public static function and(a:A, b:A):A {
return (a == "true" && b == "true") ? "true" : "false";
}
@:op(!A) public static function neg(a:A):A {
return a == "true" ? "false" : "true";
}
}
class Test {
static function main() {
var a:A = "true";
var b:A = "false";
trace(a && a);
trace(a && b);
trace(!a);
trace(!b);
}
} (And OTOH there is a requirement that an if condition is a bool, so the whole expression is coerced to one.) I"m using this in one case to overload |
I thought it"s a specified behaviour. Unless you define operators overloading for an abstract, you can"t use that abstract with those operators. |
abstract A(Int) from Int to Int {
@:to function toBool() return this != 0;
@:op(A && B) function andBool(b:Bool) return toBool() != b;
}
class Test {
static function main() {
var i:A = 1;
i && true; // Should this evaluate to `true` or to `false`?
}
} |
If there"s no If there are |
@nadako has a point here - in all other positions where exactly one type is expected, the conversions are triggered - so why not with operators that aren"t overloaded themselves? They"re just like unary or binary functions with infix notation in those cases. |
The text was updated successfully, but these errors were encountered: