Skip to content
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

Missing operator ^ for bool type #20001

Closed
alfaus opened this issue Nov 26, 2023 · 7 comments
Closed

Missing operator ^ for bool type #20001

alfaus opened this issue Nov 26, 2023 · 7 comments
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@alfaus
Copy link

alfaus commented Nov 26, 2023

Describe the bug

bool types doesn't have a xor operator

Reproduction Steps

fn main() {
  a := true
  b := false
  c := a ^ b
  assert !c
}

Expected Behavior

Program compiles

Current Behavior

Compilation ends with error: bool types only have the following operators defined: ==, !=, ||, and &&

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.3 bc62c5c

Environment details (OS name and version, etc.)

V full version: V 0.4.3 8f76a06.bc62c5c
OS: linux, Ubuntu 22.04.3 LTS
Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i3-7100 CPU @ 3.90GHz

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@alfaus alfaus added the Bug This tag is applied to issues which reports bugs. label Nov 26, 2023
@Delta456
Copy link
Member

Why will ^ work for boolean types?

@alfaus
Copy link
Author

alfaus commented Nov 26, 2023

Why not? It's a standard operator for boolean logic in every program language...

@alfaus
Copy link
Author

alfaus commented Nov 26, 2023

Into the documentation the XOR operator is presented as !=. Ok, but it is very disorienting to follow a different convention.
Maybe it should be a feature request. Sorry for my confusion.

@Delta456
Copy link
Member

Why not? It's a standard operator for boolean logic in every program language...

I haven't seen this as an operator for bools...

Look at Go: ./prog.go:8:14: invalid operation: operator ^ not defined on true (untyped bool constant)

@alfaus
Copy link
Author

alfaus commented Nov 26, 2023

Why not? It's a standard operator for boolean logic in every program language...

I haven't seen this as an operator for bools...

Look at Go: ./prog.go:8:14: invalid operation: operator ^ not defined on true (untyped bool constant)

In rust is defined as is. I think...

@JalonSolov
Copy link
Contributor

^ is "bitwise exclusive or" in C, Perl, Java, Go, and probably others.

Go example:

package main

import "fmt"

func main() {
  a := 19
  b := 21
  c := a ^ b
  fmt.Printf("The Value of c is %d\n", c)
}

Output is The Value of c is 6.

@alfaus
Copy link
Author

alfaus commented Nov 26, 2023

Thanks for the explanation.

@alfaus alfaus closed this as completed Nov 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

No branches or pull requests

3 participants