-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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 #82477 from dalexeev/gds-covariance-and-contravari…
…ance GDScript: Add return type covariance and parameter type contravariance
- Loading branch information
Showing
19 changed files
with
169 additions
and
4 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
10 changes: 10 additions & 0 deletions
10
...es/gdscript/tests/scripts/analyzer/errors/function_param_type_invalid_contravariance_1.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,10 @@ | ||
class A: | ||
func f(_p: Object): | ||
pass | ||
|
||
class B extends A: | ||
func f(_p: Node): | ||
pass | ||
|
||
func test(): | ||
pass |
2 changes: 2 additions & 0 deletions
2
...s/gdscript/tests/scripts/analyzer/errors/function_param_type_invalid_contravariance_1.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 | ||
The function signature doesn't match the parent. Parent signature is "f(Object) -> Variant". |
10 changes: 10 additions & 0 deletions
10
...es/gdscript/tests/scripts/analyzer/errors/function_param_type_invalid_contravariance_2.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,10 @@ | ||
class A: | ||
func f(_p: Variant): | ||
pass | ||
|
||
class B extends A: | ||
func f(_p: Node): # No `is_type_compatible()` misuse. | ||
pass | ||
|
||
func test(): | ||
pass |
2 changes: 2 additions & 0 deletions
2
...s/gdscript/tests/scripts/analyzer/errors/function_param_type_invalid_contravariance_2.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 | ||
The function signature doesn't match the parent. Parent signature is "f(Variant) -> Variant". |
10 changes: 10 additions & 0 deletions
10
...es/gdscript/tests/scripts/analyzer/errors/function_param_type_invalid_contravariance_3.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,10 @@ | ||
class A: | ||
func f(_p: int): | ||
pass | ||
|
||
class B extends A: | ||
func f(_p: float): # No implicit conversion. | ||
pass | ||
|
||
func test(): | ||
pass |
2 changes: 2 additions & 0 deletions
2
...s/gdscript/tests/scripts/analyzer/errors/function_param_type_invalid_contravariance_3.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 | ||
The function signature doesn't match the parent. Parent signature is "f(int) -> Variant". |
10 changes: 10 additions & 0 deletions
10
modules/gdscript/tests/scripts/analyzer/errors/function_return_type_invalid_covariance_1.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,10 @@ | ||
class A: | ||
func f() -> Node: | ||
return null | ||
|
||
class B extends A: | ||
func f() -> Object: | ||
return null | ||
|
||
func test(): | ||
pass |
2 changes: 2 additions & 0 deletions
2
modules/gdscript/tests/scripts/analyzer/errors/function_return_type_invalid_covariance_1.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 | ||
The function signature doesn't match the parent. Parent signature is "f() -> Node". |
10 changes: 10 additions & 0 deletions
10
modules/gdscript/tests/scripts/analyzer/errors/function_return_type_invalid_covariance_2.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,10 @@ | ||
class A: | ||
func f() -> Node: | ||
return null | ||
|
||
class B extends A: | ||
func f() -> Variant: # No `is_type_compatible()` misuse. | ||
return null | ||
|
||
func test(): | ||
pass |
2 changes: 2 additions & 0 deletions
2
modules/gdscript/tests/scripts/analyzer/errors/function_return_type_invalid_covariance_2.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 | ||
The function signature doesn't match the parent. Parent signature is "f() -> Node". |
10 changes: 10 additions & 0 deletions
10
modules/gdscript/tests/scripts/analyzer/errors/function_return_type_invalid_covariance_3.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,10 @@ | ||
class A: | ||
func f() -> Node: | ||
return null | ||
|
||
class B extends A: | ||
func f() -> void: # No `is_type_compatible()` misuse. | ||
return | ||
|
||
func test(): | ||
pass |
2 changes: 2 additions & 0 deletions
2
modules/gdscript/tests/scripts/analyzer/errors/function_return_type_invalid_covariance_3.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 | ||
The function signature doesn't match the parent. Parent signature is "f() -> Node". |
10 changes: 10 additions & 0 deletions
10
modules/gdscript/tests/scripts/analyzer/errors/function_return_type_invalid_covariance_4.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,10 @@ | ||
class A: | ||
func f() -> float: | ||
return 0.0 | ||
|
||
class B extends A: | ||
func f() -> int: # No implicit conversion. | ||
return 0 | ||
|
||
func test(): | ||
pass |
2 changes: 2 additions & 0 deletions
2
modules/gdscript/tests/scripts/analyzer/errors/function_return_type_invalid_covariance_4.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 | ||
The function signature doesn't match the parent. Parent signature is "f() -> float". |
20 changes: 20 additions & 0 deletions
20
modules/gdscript/tests/scripts/analyzer/features/function_param_type_contravariance.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,20 @@ | ||
class A: | ||
func int_to_variant(_p: int): pass | ||
func node_to_variant(_p: Node): pass | ||
func node_2d_to_node(_p: Node2D): pass | ||
|
||
func variant_to_untyped(_p: Variant): pass | ||
func int_to_untyped(_p: int): pass | ||
func node_to_untyped(_p: Node): pass | ||
|
||
class B extends A: | ||
func int_to_variant(_p: Variant): pass | ||
func node_to_variant(_p: Variant): pass | ||
func node_2d_to_node(_p: Node): pass | ||
|
||
func variant_to_untyped(_p): pass | ||
func int_to_untyped(_p): pass | ||
func node_to_untyped(_p): pass | ||
|
||
func test(): | ||
pass |
1 change: 1 addition & 0 deletions
1
modules/gdscript/tests/scripts/analyzer/features/function_param_type_contravariance.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 @@ | ||
GDTEST_OK |
32 changes: 32 additions & 0 deletions
32
modules/gdscript/tests/scripts/analyzer/features/function_return_type_covariance.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,32 @@ | ||
class A: | ||
func variant_to_int() -> Variant: return 0 | ||
func variant_to_node() -> Variant: return null | ||
func node_to_node_2d() -> Node: return null | ||
|
||
func untyped_to_void(): pass | ||
func untyped_to_variant(): pass | ||
func untyped_to_int(): pass | ||
func untyped_to_node(): pass | ||
|
||
func void_to_untyped() -> void: pass | ||
func variant_to_untyped() -> Variant: return null | ||
func int_to_untyped() -> int: return 0 | ||
func node_to_untyped() -> Node: return null | ||
|
||
class B extends A: | ||
func variant_to_int() -> int: return 0 | ||
func variant_to_node() -> Node: return null | ||
func node_to_node_2d() -> Node2D: return null | ||
|
||
func untyped_to_void() -> void: pass | ||
func untyped_to_variant() -> Variant: return null | ||
func untyped_to_int() -> int: return 0 | ||
func untyped_to_node() -> Node: return null | ||
|
||
func void_to_untyped(): pass | ||
func variant_to_untyped(): pass | ||
func int_to_untyped(): pass | ||
func node_to_untyped(): pass | ||
|
||
func test(): | ||
pass |
1 change: 1 addition & 0 deletions
1
modules/gdscript/tests/scripts/analyzer/features/function_return_type_covariance.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 @@ | ||
GDTEST_OK |