-
Notifications
You must be signed in to change notification settings - Fork 27
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
base: main
Are you sure you want to change the base?
Conversation
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
@DoomTas3r could you review? For some reason I can't add you to the reviewers list. |
There was a problem hiding this 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 = { |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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:
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.
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