You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-19 14:31:59 +00:00
GDScript: Consolidate behavior for assigning enum types
This makes sure that assigning values to enum-typed variables are consistent. Same enum is always valid, different enum is always invalid (without casting) and assigning `int` creates a warning if there is no casting. There are new test cases to ensure this behavior doesn't break in the future.
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
enum MyEnum { ENUM_VALUE_1, ENUM_VALUE_2 }
|
||||
|
||||
# Assigning int value to enum-typed variable without explicit cast causes a warning.
|
||||
# While it is valid it may be a mistake in the assignment.
|
||||
var class_var: MyEnum = 0
|
||||
|
||||
func test():
|
||||
print(class_var)
|
||||
class_var = 1
|
||||
print(class_var)
|
||||
|
||||
var local_var: MyEnum = 0
|
||||
print(local_var)
|
||||
local_var = 1
|
||||
print(local_var)
|
||||
@@ -0,0 +1,21 @@
|
||||
GDTEST_OK
|
||||
>> WARNING
|
||||
>> Line: 5
|
||||
>> INT_ASSIGNED_TO_ENUM
|
||||
>> Integer used when an enum value is expected. If this is intended cast the integer to the enum type.
|
||||
>> WARNING
|
||||
>> Line: 9
|
||||
>> INT_ASSIGNED_TO_ENUM
|
||||
>> Integer used when an enum value is expected. If this is intended cast the integer to the enum type.
|
||||
>> WARNING
|
||||
>> Line: 12
|
||||
>> INT_ASSIGNED_TO_ENUM
|
||||
>> Integer used when an enum value is expected. If this is intended cast the integer to the enum type.
|
||||
>> WARNING
|
||||
>> Line: 14
|
||||
>> INT_ASSIGNED_TO_ENUM
|
||||
>> Integer used when an enum value is expected. If this is intended cast the integer to the enum type.
|
||||
0
|
||||
1
|
||||
0
|
||||
1
|
||||
Reference in New Issue
Block a user