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

bool -> (int, float) and (int, float) -> bool implicit cast removed #40336

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ThakeeNathees
Copy link
Contributor

@ThakeeNathees ThakeeNathees commented Jul 13, 2020

Fix: #40249
Fix #26248

Capture

@Calinou Calinou added this to the 4.0 milestone Jul 13, 2020
@Calinou Calinou added the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Jul 13, 2020
@dalexeev
Copy link
Member

Note that the following code will no longer work:

func _item_selected(idx: int) -> void:
    get_tree().debug_collisions_hint = idx & 0b01
    get_tree().debug_navigation_hint = idx & 0b10

Explicit conversion will be required:

func _item_selected(idx: int) -> void:
    get_tree().debug_collisions_hint = bool(idx & 0b01)
    get_tree().debug_navigation_hint = bool(idx & 0b10)

@ThakeeNathees
Copy link
Contributor Author

if we support implicit casting between boolean and numerical types than it also needs to support arithmetic operations too. the below line should be valid (it's not now).

dir.x = Input.is_key_pressed(KEY_A) - Input.is_key_pressed(KEY_D);

@aaronfranke
Copy link
Member

@ThakeeNathees Is this still desired? If so, this needs to be rebased on the latest master branch.

@ThakeeNathees ThakeeNathees force-pushed the bool-to-float_int-cast-removed branch from 866abe3 to 00020e5 Compare January 20, 2021 12:36
@ThakeeNathees
Copy link
Contributor Author

@aaronfranke done

@YuriSizov YuriSizov requested a review from a team August 24, 2021 23:26
@akien-mga akien-mga added topic:core and removed cherrypick:3.x Considered for cherry-picking into a future 3.x release labels Feb 12, 2023
@akien-mga akien-mga modified the milestones: 4.0, 4.x Feb 12, 2023
@MewPurPur
Copy link
Contributor

Sooo what's the status on this?

@Calinou
Copy link
Member

Calinou commented Jul 31, 2023

Sooo what's the status on this?

This is a compatibility-breaking change, so I think it should be implemented as a GDScript warning instead. (I think this may already exists as "unsafe cast" or "unsafe assignment".)

We may want a specific warning for those particular bool-to-int/float cases (and vice versa) though. This one could be enabled by default in projects created after this PR is merged (using the approach described in godotengine/godot-proposals#4834).

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

Successfully merging this pull request may close these issues.

Bools are implicitly cast to ints Gdscript -> Assign a boolean value to a typed float produces no error.
6 participants