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:
+10
@@ -0,0 +1,10 @@
|
||||
enum MyEnum { ENUM_VALUE_1, ENUM_VALUE_2 }
|
||||
enum MyOtherEnum { OTHER_ENUM_VALUE_1, OTHER_ENUM_VALUE_2 }
|
||||
|
||||
# Different enum types can't be assigned without casting.
|
||||
var class_var: MyEnum = MyEnum.ENUM_VALUE_1
|
||||
|
||||
func test():
|
||||
print(class_var)
|
||||
class_var = MyOtherEnum.OTHER_ENUM_VALUE_2
|
||||
print(class_var)
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
GDTEST_ANALYZER_ERROR
|
||||
Cannot assign a value of type "MyOtherEnum (enum)" to a target of type "MyEnum (enum)".
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
enum MyEnum { ENUM_VALUE_1, ENUM_VALUE_2 }
|
||||
enum MyOtherEnum { OTHER_ENUM_VALUE_1, OTHER_ENUM_VALUE_2 }
|
||||
|
||||
# Different enum types can't be assigned without casting.
|
||||
var class_var: MyEnum = MyOtherEnum.OTHER_ENUM_VALUE_1
|
||||
|
||||
func test():
|
||||
print(class_var)
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
GDTEST_ANALYZER_ERROR
|
||||
Value of type "MyOtherEnum (enum)" cannot be assigned to a variable of type "MyEnum (enum)".
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
enum MyEnum { ENUM_VALUE_1, ENUM_VALUE_2 }
|
||||
enum MyOtherEnum { OTHER_ENUM_VALUE_1, OTHER_ENUM_VALUE_2 }
|
||||
|
||||
func test():
|
||||
var local_var: MyEnum = MyEnum.ENUM_VALUE_1
|
||||
print(local_var)
|
||||
local_var = MyOtherEnum.OTHER_ENUM_VALUE_2
|
||||
print(local_var)
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
GDTEST_ANALYZER_ERROR
|
||||
Cannot assign a value of type "MyOtherEnum (enum)" to a target of type "MyEnum (enum)".
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
enum MyEnum { ENUM_VALUE_1, ENUM_VALUE_2 }
|
||||
enum MyOtherEnum { OTHER_ENUM_VALUE_1, OTHER_ENUM_VALUE_2 }
|
||||
|
||||
func test():
|
||||
var local_var: MyEnum = MyOtherEnum.OTHER_ENUM_VALUE_1
|
||||
print(local_var)
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
GDTEST_ANALYZER_ERROR
|
||||
Value of type "MyOtherEnum (enum)" cannot be assigned to a variable of type "MyEnum (enum)".
|
||||
Reference in New Issue
Block a user