-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Incorrect array element type error for arg when method is called on non-typed class property with non-typed arg #86963
Comments
This is expected behavior, although not obvious. An array literal ( This will be fixed when we add a typed array constructor ( |
Alright, makes sense. Doesn't that make the error message technically incorrect tho?
Shouldn't it be something like
|
I don't get why this works tho: var local = C.new()
local.trouble_maker([""])
print("local works") |
By default, GDScript produces no errors/warnings if the source's static type is a supertype of the target's type (in other words, wider than expected). GDScript generates static errors only if it's guaranteed that the code is incorrect, otherwise static analyzer leaves this check for runtime. At runtime, we know the exact types, so "cannot be verified" is incorrect.
There is some inconsistency in how weak type inference works for local variables. The type of initializer expression of a local variable is used as its type, if you don't explicitly specify type and even don't use Note: In theory, unless you assign a local variable to something else, it cannot change its type (unlike a member variable, which can be changed "between the lines"), so GDScript could treat the variable as if it were explicitly declared statically typed (but in practice, the GDScript compiler is not so smart and does not currently use SSA optimizations). |
Ok that all makes a lot of sense! Thanks for taking the time to explain :) |
Tested versions
v4.2.1.stable.arch_linux
System information
Arch Linux
Issue description
A class has a method (
some_method
) that accepts anArray[String]
.some_method
is called with an array containing a constant.If the class instance is stored as a non-typed property (of another class) and the method is called with an identical array, the engine raises a type error.
Steps to reproduce
Code:
Output:
Error:
Minimal reproduction project (MRP)
mrp.zip
Minimal reproduction script
to get the error, run
f()
The text was updated successfully, but these errors were encountered: