GNOME Bugzilla – Bug 727927
Unary +/- can't be used for enums
Last modified: 2018-05-22 15:08:05 UTC
Created attachment 273948 [details] Negation of enum fails The attached test case fails to compile with the error "Operator not supported for `Direction'". I think Vala should support this since writing (-1 * d) works as expected.
Created attachment 273949 [details] [review] Support negation of enums Fixes bug 727927
Created attachment 273957 [details] [review] Support negation of enums The previous patch contained only the testcase, this is the actual fix.
This is not a good operation for enums. The + and - are supposed to return a value in the same domain, which is not the case for enums. If you want + and -, cast to int.
Ok that makes sense, but then the bug is at the binary operations, consider the following: var foo = Some.FOO; var bar = foo * 5; ccode: Foo foo = 0; Foo bar = 0; foo = SOME_FOO; bar = foo * 5; // should have int as result type
Yes never liked that, with enums I'd allow only bitwise operators. However that can't be changed anymore.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/441.