mirror of
https://github.com/godotengine/godot.git
synced 2026-01-05 06:11:29 +03:00
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:
@@ -1,2 +1,11 @@
|
||||
func test():
|
||||
var __
|
||||
var unassigned
|
||||
print(unassigned)
|
||||
unassigned = "something" # Assigned only after use.
|
||||
|
||||
var a
|
||||
print(a) # Unassigned, warn.
|
||||
if a: # Still unassigned, warn.
|
||||
a = 1
|
||||
print(a) # Assigned (dead code), don't warn.
|
||||
print(a) # "Maybe" assigned, don't warn.
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
GDTEST_OK
|
||||
>> WARNING
|
||||
>> Line: 2
|
||||
>> Line: 3
|
||||
>> UNASSIGNED_VARIABLE
|
||||
>> The variable "__" was used but never assigned a value.
|
||||
>> The variable "unassigned" was used before being assigned a value.
|
||||
>> WARNING
|
||||
>> Line: 7
|
||||
>> UNASSIGNED_VARIABLE
|
||||
>> The variable "a" was used before being assigned a value.
|
||||
>> WARNING
|
||||
>> Line: 8
|
||||
>> UNASSIGNED_VARIABLE
|
||||
>> The variable "a" was used before being assigned a value.
|
||||
<null>
|
||||
<null>
|
||||
<null>
|
||||
|
||||
Reference in New Issue
Block a user