Inherit parent method return types for untyped overrides

This commit is contained in:
Leonard Pop 2026-02-02 17:05:40 +02:00
parent f4f0679a2d
commit 058a46f154
11 changed files with 93 additions and 9 deletions

View file

@ -0,0 +1,22 @@
class A:
func return_int(_variant: Variant) -> int: return 123
func return_int_array(_variant: Variant) -> Array[int]: return [1]
func return_int_dict(_variant: Variant) -> Dictionary[int, int]: return {1: 1}
func return_node(_variant: Variant) -> Node: return null
class B extends A:
func return_int(variant: Variant): return variant
func return_int_array(variant: Variant): return variant
func return_int_dict(variant: Variant): return variant
func return_node(variant: Variant): return variant
func output(value: Variant) -> void:
print(var_to_str(value).replace("\n", ""))
func test():
var b := B.new()
output(b.return_int("abc"))
output(b.return_int_array("abc"))
output(b.return_int_dict("abc"))
output(b.return_node("abc"))

View file

@ -0,0 +1,9 @@
GDTEST_RUNTIME_ERROR
>> SCRIPT ERROR at runtime/errors/untyped_override_return_incompatible_value.gd:8 on B.return_int(): Trying to return value of type "String" from a function whose return type is "int".
0
>> SCRIPT ERROR at runtime/errors/untyped_override_return_incompatible_value.gd:9 on B.return_int_array(): Trying to return value of type "String" from a function whose return type is "Array[int]".
Array[int]([])
>> SCRIPT ERROR at runtime/errors/untyped_override_return_incompatible_value.gd:10 on B.return_int_dict(): Trying to return a value of type "String" where expected return type is "Dictionary[int, int]".
Dictionary[int, int]({})
>> SCRIPT ERROR at runtime/errors/untyped_override_return_incompatible_value.gd:11 on B.return_node(): Trying to return value of type "String" from a function whose return type is "Node".
null