Open kester-habermann opened 2 weeks ago
This is not a bug, the fields you mentioned are not booleans but enums^1. It just so happens to work due to implicit conversions making OFF = 0 = false
and ON = 1 = true
.
But with strict typing (e.g. gdscript knows that there is a type mismatch), it definitely should error for these assignments out of the box. Not every enum represents "on/off with additional values", so IMO it's a feature request to allow these conversions with strict typing enabled.
My bad, I didn't look closely enough at the documentation. I was really under the impression that these were supposed to be booleans. Thanks for the quick reply! I try it with strict typing and using the correct enum values.
I guess this is not a bug but it seems like the enum types for these are not explicit, During explicit casting, it still seems like you can declare any int's as bool enum's.
We have some inconsistency with implicit conversions (between bool
, int
, float
, and enums; String
, StringName
, and NodePath
; Array
, and Packed*Array
; etc.). Sometimes the analyzer reports an error where it works at runtime for untyped code. I am not a fan of implicit conversions, but I think we should approach this in a consistent way.
There probably shouldn't be a compile-time error if it works at runtime, but warnings would be useful in some cases. There are already NARROWING_CONVERSION
and INT_AS_ENUM_WITHOUT_CAST
, but they don't cover all cases. But a general IMPLICIT_CONVERSION
warning would be annoying for many users, especially in cases int
to float
, String
to StringName
, String
to NodePath
. The warning would only be suitable for strict mode, like INFERRED_DECLARATION
.
Tested versions
Godot Engine v4.3.stable.official.77dcf97d8 Godot Engine v4.4.dev3.official.f4af8201b
System information
Godot v4.4.dev3 - Debian GNU/Linux 12 (bookworm) 12 on X11 - X11 display driver, Multi-window, 1 monitor - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 4080 SUPER (nvidia) - AMD Ryzen 9 5900X 12-Core Processor (24 threads)
Issue description
This code does not compile:
The editor shows this error:
changing it to this, it works:
This code has the same problem:
Assignment of other non-boolean attributes works without problems when using the typed instance, e. g. this works:
Steps to reproduce
Minimal reproduction project (MRP)
new-game-project.zip