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

Transmuted boolean fails comparison with untyped boolean #4824

Open
davysson opened this issue Feb 10, 2025 · 0 comments
Open

Transmuted boolean fails comparison with untyped boolean #4824

davysson opened this issue Feb 10, 2025 · 0 comments

Comments

@davysson
Copy link

Context

From my understanding, when transmuting a value to a bool the behavior should be similar to C where zero is considered false and anything else is considered true. The problem arises when trying to transmute a value that is neither zero nor one. While there is no error, the resulting boolean is never equal to the untyped boolean "true".

  • Operating System & Odin Version:
Odin:    dev-2025-01-nightly
OS:      Bazzite 41 (FROM Fedora Silverblue), Linux 6.12.12-203.bazzite.fc41.x86_64
CPU:     AMD Ryzen 9 5900X 12-Core Processor
RAM:     31986 MiB
Backend: LLVM 18.1.6

Expected Behavior

Transmuted boolean should be equal to untyped boolean "true".

Current Behavior

The comparison returns "false".

Failure Information (for bugs)

Please help provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template.

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

package main

import "core:fmt"

main :: proc() {

	bool_1_transmuted := transmute(bool)u8(1)
	bool_2_transmuted := transmute(bool)u8(2)

	fmt.println(bool_1_transmuted, bool_1_transmuted == true) // prints: true true
	fmt.println(bool_2_transmuted, bool_2_transmuted == true) // prints: true false but should print true true
	assert(bool_1_transmuted) // true
	assert(bool_1_transmuted == true) // true
	assert(bool_2_transmuted) // true
	assert(bool_2_transmuted == true) // false but should be  true
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant