diff options
Diffstat (limited to 'modules/gdscript/tests')
9 files changed, 79 insertions, 0 deletions
diff --git a/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_before_declared.gd b/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_before_declared.gd new file mode 100644 index 0000000000..7cdc14685f --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_before_declared.gd @@ -0,0 +1,5 @@ +enum MyEnum {} + +func test(): + var e: E + const E = MyEnum diff --git a/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_before_declared.out b/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_before_declared.out new file mode 100644 index 0000000000..e1d5837f32 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_before_declared.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Local constant "E" is not resolved at this point. diff --git a/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_const.gd b/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_const.gd new file mode 100644 index 0000000000..68cf5efd8b --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_const.gd @@ -0,0 +1,5 @@ +enum MyEnum {} + +func test(): + var E = MyEnum + var e: E diff --git a/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_const.out b/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_const.out new file mode 100644 index 0000000000..b1f4e7a2c8 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_const.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Local variable "E" cannot be used as a type. diff --git a/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_type.gd b/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_type.gd new file mode 100644 index 0000000000..ac446183cb --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_type.gd @@ -0,0 +1,5 @@ +enum MyEnum {A} + +func test(): + const E = MyEnum.A + var e: E diff --git a/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_type.out b/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_type.out new file mode 100644 index 0000000000..c3c2c8ca2f --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_type.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Local constant "E" is not a valid type. diff --git a/modules/gdscript/tests/scripts/analyzer/features/local_const_as_type.gd b/modules/gdscript/tests/scripts/analyzer/features/local_const_as_type.gd new file mode 100644 index 0000000000..90c7f893b1 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/local_const_as_type.gd @@ -0,0 +1,41 @@ +class InnerClass: + enum InnerEnum {A = 2} + const INNER_CONST = "INNER_CONST" + +enum Enum {A = 1} + +const Other = preload("./local_const_as_type.notest.gd") + +func test(): + const IC = InnerClass + const IE = IC.InnerEnum + const E = Enum + # Doesn't work in CI, but works in the editor. Looks like an unrelated bug. TODO: Investigate it. + # Error: Invalid call. Nonexistent function 'new' in base 'GDScript'. + var a1: IC = null # IC.new() + var a2: IE = IE.A + var a3: IC.InnerEnum = IE.A + var a4: E = E.A + print(a1.INNER_CONST) + print(a2) + print(a3) + print(a4) + + const O = Other + const OV: Variant = Other # Removes metatype. + const OIC = O.InnerClass + const OIE = OIC.InnerEnum + const OE = O.Enum + var b: O = O.new() + @warning_ignore("unsafe_method_access") + var bv: OV = OV.new() + var b1: OIC = OIC.new() + var b2: OIE = OIE.A + var b3: O.InnerClass.InnerEnum = OIE.A + var b4: OE = OE.A + print(b.CONST) + print(bv.CONST) + print(b1.INNER_CONST) + print(b2) + print(b3) + print(b4) diff --git a/modules/gdscript/tests/scripts/analyzer/features/local_const_as_type.notest.gd b/modules/gdscript/tests/scripts/analyzer/features/local_const_as_type.notest.gd new file mode 100644 index 0000000000..f16cdc18d8 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/local_const_as_type.notest.gd @@ -0,0 +1,6 @@ +class InnerClass: + enum InnerEnum {A = 20} + const INNER_CONST = "OTHER_INNER_CONST" + +enum Enum {A = 10} +const CONST = "OTHER_CONST" diff --git a/modules/gdscript/tests/scripts/analyzer/features/local_const_as_type.out b/modules/gdscript/tests/scripts/analyzer/features/local_const_as_type.out new file mode 100644 index 0000000000..b00024de2c --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/local_const_as_type.out @@ -0,0 +1,11 @@ +GDTEST_OK +INNER_CONST +2 +2 +1 +OTHER_CONST +OTHER_CONST +OTHER_INNER_CONST +20 +20 +10 |