Odin icon indicating copy to clipboard operation
Odin copied to clipboard

Cannot cast untyped bool to integer

Open goldenbergdaniel opened this issue 1 year ago • 3 comments

Context

Odin: dev-2024-07:b4ca044ae OS: macOS Sonoma 14 (build: 23A344, kernel: 23.0.0) CPU: Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz RAM: 8192 MiB Backend: LLVM 18.1.7

Expected Behavior

Should be able to cast an untyped boolean expression to an integer.

Current Behavior

  1. int(2 < 1) == 0 // Error: Cannot cast '2 < 1' as 'int' from 'untyped bool'
  2. int(true) == 0 // Error: Cannot cast 'true' as 'int' from 'untyped bool'
  3. int(my_bool) == 0 // Success

goldenbergdaniel avatar Jul 25 '24 21:07 goldenbergdaniel

@gingerBill seems to have explicitly disabled this in 3fc60930 , assigning to him for clarity

laytan avatar Aug 11 '24 19:08 laytan

I encountered this when playing around with Raylib - setting boolean shader values seems to be a bit verbose due to this.

I have to do this:

gamma := false
igamma := c.int(gamma)
rl.SetShaderValue(g.skybox_shader, gamma_loc, &gamma, .INT)

Instead of:

gamma := c.int(false)
rl.SetShaderValue(g.skybox_shader, gamma_loc, &gamma, .INT)

Not the biggest deal in the world since I'll just wrap this in a proc and forget about it.

chip2n avatar May 15 '25 16:05 chip2n

This looks to be an issue still, as even forcing the untyped bool to a typed one does not permit type conversion:

	fmt.println(int(bool(true)))
	fmt.println(i32(b32(true)))
	fmt.println(i64(b64(true)))

None of these statements compile, yet if the values are first assigned to a variable, then they may be converted.

Feoramund avatar Jun 02 '25 12:06 Feoramund