-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80964 from dalexeev/gds-allow-use-local-consts-as…
…-types GDScript: Allow use local constants as types
- Loading branch information
Showing
12 changed files
with
235 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_before_declared.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
enum MyEnum {} | ||
|
||
func test(): | ||
var e: E | ||
const E = MyEnum |
2 changes: 2 additions & 0 deletions
2
modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_before_declared.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
GDTEST_ANALYZER_ERROR | ||
Local constant "E" is not resolved at this point. |
5 changes: 5 additions & 0 deletions
5
modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_const.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
enum MyEnum {} | ||
|
||
func test(): | ||
var E = MyEnum | ||
var e: E |
2 changes: 2 additions & 0 deletions
2
modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_const.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
GDTEST_ANALYZER_ERROR | ||
Local variable "E" cannot be used as a type. |
5 changes: 5 additions & 0 deletions
5
modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_type.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
enum MyEnum {A} | ||
|
||
func test(): | ||
const E = MyEnum.A | ||
var e: E |
2 changes: 2 additions & 0 deletions
2
modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_type.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
GDTEST_ANALYZER_ERROR | ||
Local constant "E" is not a valid type. |
41 changes: 41 additions & 0 deletions
41
modules/gdscript/tests/scripts/analyzer/features/local_const_as_type.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
Oops, something went wrong.