EndlessLife
EndlessLife

Reputation: 318

Dart Editor bitwise XOR showing as unknown

The current version of Dart Editor is showing the bitwise XOR operator as not defined for class bool

I don't see it defined in num.dart either.

Ex:

bool x = a ^ b;

The editor shows the "Caret" as not defined.

Update: Dart's api spec only allows bitwise XOR on integers. I fixed my code to properly work with bools.

Upvotes: 5

Views: 7131

Answers (2)

Guilherme Matuella
Guilherme Matuella

Reputation: 2273

You can use the XOR operator on booleans since Dart version 2.1

[...] since Dart 2.1, the bool class has had non-short-circuit operators &, | and ^.

They can be used where you want both sides to be evaluated, and, especially for ^, they can be used in assignments: bool parity = false; while (something) parity ^= checkSomething();.

Taken from the corresponding Github issue.

See the dart documentation for XOR here.

Upvotes: 4

Danny Tuppeny
Danny Tuppeny

Reputation: 42383

(Copied from the question, so that this appears as answered...)

Dart's spec only allows bitwise XOR on integers.

Upvotes: 2

Related Questions