-
-
Notifications
You must be signed in to change notification settings - Fork 20.3k
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
Gdscript - should generate an error when adding (append) an element of a different type that does not match a typed array - No type validation errors will be generated, and the array will not have the element added #86851
Comments
You get an error though:
Not a parse error here, this is a runtime check |
Hi @AThousandShips, print(array1) In fact, append() "works", but it DOES NOT add the element and does not generate an error. For me the append should have already given the error. An improvement would be if the editor itself at design time already issued an alert such as those lines that have a red background, even so, the error at runtime for me is right at append() with an "instant crash". I believe that if it continues as it is, it will be a point of friction for hobbyist programming users. Therefore, I thank you for your attention and if you still consider a point that does not need improvement, just close the bug.
|
Look in the debugger, the error is there |
Is there a reason why this does not show in the Godot output console like all the other user errors? This is indeed unintuitive, and I was also under the impression that it failed silently. |
It's a runtime error, they generally are in the debugger, by design I believe, unsure |
For me it's a big problem because it can hide bugs in the gdscript code. We must remember that not every GDscript user is a professional programmer/software engineer who understands the smallest details. |
@LeandroHPerez You didn't actually add a MRP, just some text that says "array_error.zip".
It does give you an error though, you're not meant to ignore the red Debugger text that indicates you have errors, they are not hidden, so I can't agree that it hides bugs in code. I will say that you are using a If you use Typed arrays seem to give only a runtime error, they are special types and I'm not sure how feasible it is to change this: But an error is an error, you're not meant to ignore these. After running the game, I think the user is expected to notice the red "Debugger" text and have a look. |
This wouldn't really be easy to convert into a different type of error This is an error that happens in I'd say that it's not feasible to change this, and it's instead something you need to pay attention to, it isn't hidden, it shows up as a red marker in the bottom bar, as your screenshot clearly displays 🙂 |
@Lippanon Ops, relayy sorry for this: "You didn't actually add a MRP, just some text that says "array_error.zip". |
@Lippanon "will say that you are using a typed Array of PackedVector2Array in your screenshots, this is unusual if you're a begginer. Are you sure you intend to use that instead of simply PackedVector2Array?"" Yes, I intend to. I will fill it with a huge list of points and indices representing many polygons Like this example in documentation, but with thousands of points and indices: Therefore, I was forced to use these "exotic data types". In fact, now I created a custom class and I will have a typed array of it "var array_with_tile_representation: Array[TileRepresentation] where is my custom class It's hard to know what a user will do... In the sense of beginner users, it's more because I care a lot about them, some points that may seem obvious to very experienced devs, who deal with ultra complex projects like Godot, are not obvious to most users of the tool, believe me. Anything that can be made simpler is always welcome. In the case of game development, I'm a complete beginner. |
There are no static checks because generic types are not fully implemented. Type inference is only implemented for the index operation ( As for runtime checks, they are do not cause the debugger to stop (like many other code executed by the core, not GDScript), see the Errors tab instead of Stack Trace. I'm not sure about this, but I think the reason for not using the debugger is performance. |
This bit me today. I wrote the wrong type for the parameters of a function, and the array wasn't filled because of that as the code in that function was appending the wrong type to that array. in my mind, a type error should stop the game from running. That's the whole point of giving type information about data : documenting expectations about types and trust that the types are enforced. It does in other cases, so that missing part in append easily catch you off guard. ( I didn't look in the errors panel because most errors there are actually harmless warnings and but also because giving a type to an array is a bit of work you do to avoid to have to look. You document the correct state of the system, it should not run at all if it is isn't in that state ). I don't case as much about the runtime vs compile time distinction, but having confidence in the typing system is important. |
There's a related proposal here: godotengine/godot-proposals#1729 Having a generic "pause on error" project setting might be useful, but it can hinder productivity as many errors can be difficult to resolve during development or are unintended due to bugs. |
My personal preference would be to distinguish coding errors from content errors even if they both eventually bubble up to the editor. Coding has it own workflow, and having a specific channel for code errors would be useful to have better integration into IDE/Editors. Also content is more flexible, prone to many movement and errors that are transient. |
Tested versions
Godot 4.2.1 without .net
System information
Macbook Apple M2 Pro - MacOs Sonoma 14.2.1
Issue description
Create a typed array and add an element of different type to it.
No type validation errors will be generated, and the array will not have the element added
Steps to reproduce
Resume: call this simple Gdscript function attached and see what happens when trying append an value that doesn't match with array type
Steps:
1- call attached script function test_typed_array_data01() inside Godot 4.2.1 without .net on any node, inside func _ready(), just call it.
2- See lines where .append() is called passing an arg of type String and not one that combine/match with type of array
3- See stacktrace errors and when it happens
4- Comment lines like print 02 in the editor, save
5- reexecute steps 1,2,3
Expected result:
And if not a parse error for sure a runtime error, but it should occur in .append() line and not in line like this:
print(str(array1[0])) or print(str(array2[0]))
When i call an line like print(str(array1[0])) this array has zero size where i expect that had an value...
Evidences:
1)
Minimal reproduction project (MRP)
Just call this GDscript function:
func test_typed_array_data01():
The text was updated successfully, but these errors were encountered: