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

Fix types relationships #352

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

Fix types relationships #352

wants to merge 1 commit into from

Conversation

manuq
Copy link
Contributor

@manuq manuq commented Jan 6, 2025

The types relationship (previously named cast_relationships) tell which type can be used in the context of another type. For example, integers and floats are exchangeable. And in particular, all other types can be used in boolean context: if not Color.BLACK: is allowed in GDScript as Color.BLACK is falsey. Same for the empty string, zero number, etc.

This fixes a bug where an integer or float value block was allowed to be snapped into a string slot.

This removes outdated custom casting code that has been abandoned.

#351

The types relationship (previously named cast_relationships) tell which
type can be used in the context of another type. For example, integers
and floats are exchangeable. And in particular, all other types can be
used in boolean context: `if not Color.BLACK:` is allowed in GDScript as
Color.BLACK is falsey. Same for the empty string, zero number, etc.

This fixes a bug where an integer or float value block was allowed to be
snapped into a string slot.

This removes outdated custom casting code that has been abandoned.

#351
@manuq
Copy link
Contributor Author

manuq commented Jan 6, 2025

@DoomTas3r could you review? For some reason I can't add you to the reviewers list.

Copy link
Contributor

@DoomTas3r DoomTas3r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as intended by preventing casting as strings from other types.

dist[v] = alt
prev[v] = CastGraphEdge.new(u, edge.cast_format)
queue.update_priority(v, alt)
const types_relationships = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks much cleaner, although I found casting to a boolean works in if statements or converting through a boolean block, but not for directly setting a boolean variable (Parser Error: Value of type "String" cannot be assigned to a variable of type "bool".) but that situation is unlikely due to it's unique shape. I also think that boolean to integer could be added in the future, similar to #267 (true => 1, false => 0).

Copy link
Contributor Author

@manuq manuq Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks much cleaner, although I found casting to a boolean works in if statements or converting through a boolean block, but not for directly setting a boolean variable (Parser Error: Value of type "String" cannot be assigned to a variable of type "bool".) but that situation is unlikely due to it's unique shape. I also think that boolean to integer could be added in the future, similar to #267 (true => 1, false => 0).

Oh right, good catch. The assignment is a problem. The issue was there before. For example:
Captura desde 2025-01-06 11-59-05

Which gives: Parser Error: Value of type "Vector2" cannot be assigned to a variable of type "bool".

This PR makes it a bit worse, allowing for more value blocks to be snapped in boolean setters.

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

Successfully merging this pull request may close these issues.

2 participants