mirror of
https://github.com/godotengine/godot.git
synced 2026-01-03 18:11:19 +03:00
GDScript: Report property type errors
Inline getters & setters are now FunctionNodes. Their names are set in the parser, not in the compiler. GDScript-Analyzer will now run through getter and setter. Also report wrong type or signature errors regarding getset properties. Added GDScript tests for getters and setters. #53102
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
var _prop : int
|
||||
|
||||
# Getter function has wrong return type.
|
||||
var prop : String:
|
||||
get = get_prop
|
||||
|
||||
func get_prop():
|
||||
return _prop
|
||||
|
||||
func test():
|
||||
pass
|
||||
@@ -0,0 +1,2 @@
|
||||
GDTEST_ANALYZER_ERROR
|
||||
Function with return type "int" cannot be used as getter for a property of type "String".
|
||||
@@ -0,0 +1,11 @@
|
||||
var _prop : int
|
||||
|
||||
# Setter function has wrong argument type.
|
||||
var prop : String:
|
||||
set = set_prop
|
||||
|
||||
func set_prop(value : int):
|
||||
_prop = value
|
||||
|
||||
func test():
|
||||
pass
|
||||
@@ -0,0 +1,2 @@
|
||||
GDTEST_ANALYZER_ERROR
|
||||
Function with argument type "int" cannot be used as setter for a property of type "String".
|
||||
@@ -0,0 +1,9 @@
|
||||
var _prop : int
|
||||
|
||||
# Inline getter returns int instead of String.
|
||||
var prop : String:
|
||||
get:
|
||||
return _prop
|
||||
|
||||
func test():
|
||||
pass
|
||||
@@ -0,0 +1,2 @@
|
||||
GDTEST_ANALYZER_ERROR
|
||||
Cannot return value of type "int" because the function return type is "String".
|
||||
@@ -0,0 +1,9 @@
|
||||
var _prop : int
|
||||
|
||||
# Inline setter assigns String to int.
|
||||
var prop : String:
|
||||
set(value):
|
||||
_prop = value
|
||||
|
||||
func test():
|
||||
pass
|
||||
@@ -0,0 +1,2 @@
|
||||
GDTEST_ANALYZER_ERROR
|
||||
Cannot assign a value of type "String" to a target of type "int".
|
||||
Reference in New Issue
Block a user