GDScript: Don't warn on unassigned for builtin-typed variables
If the type of a variable is a built-in Variant type, then it will automatically be assigned a default value based on the type. This means that the explicit initialization may be unnecessary. Thus this commit removes the warning in such case. This also changes the meaning of the unassigned warning to happen when the variable is used before being assigned, not when it has zero assignments.
This commit is contained in:
parent
a7b860250f
commit
877802e252
10 changed files with 65 additions and 30 deletions
|
|
@ -11,6 +11,7 @@ class InnerClass:
|
|||
var e2: InnerClass.MyEnum
|
||||
var e3: EnumTypecheckOuterClass.InnerClass.MyEnum
|
||||
|
||||
@warning_ignore("unassigned_variable")
|
||||
print("Self ", e1, e2, e3)
|
||||
e1 = MyEnum.V1
|
||||
e2 = MyEnum.V1
|
||||
|
|
@ -48,6 +49,7 @@ func test_outer_from_outer():
|
|||
var e1: MyEnum
|
||||
var e2: EnumTypecheckOuterClass.MyEnum
|
||||
|
||||
@warning_ignore("unassigned_variable")
|
||||
print("Self ", e1, e2)
|
||||
e1 = MyEnum.V1
|
||||
e2 = MyEnum.V1
|
||||
|
|
@ -66,6 +68,7 @@ func test_inner_from_outer():
|
|||
var e1: InnerClass.MyEnum
|
||||
var e2: EnumTypecheckOuterClass.InnerClass.MyEnum
|
||||
|
||||
@warning_ignore("unassigned_variable")
|
||||
print("Inner ", e1, e2)
|
||||
e1 = InnerClass.MyEnum.V1
|
||||
e2 = InnerClass.MyEnum.V1
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
# GH-88117, GH-85796
|
||||
|
||||
func test():
|
||||
var array: Array
|
||||
# Should not emit unassigned warning because the Array type has a default value.
|
||||
array.assign([1, 2, 3])
|
||||
print(array)
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
GDTEST_OK
|
||||
[1, 2, 3]
|
||||
|
|
@ -31,8 +31,8 @@ func int_func() -> int:
|
|||
func test_warnings(unused_private_class_variable):
|
||||
var t = 1
|
||||
|
||||
@warning_ignore("unassigned_variable")
|
||||
var unassigned_variable
|
||||
@warning_ignore("unassigned_variable")
|
||||
print(unassigned_variable)
|
||||
|
||||
var _unassigned_variable_op_assign
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue