1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-10 13:00:37 +00:00

Merge pull request #53103 from ZuBsPaCe/gdscript-analyze-properties-fix

GDScript: Report property type errors
This commit is contained in:
George Marques
2021-10-11 11:01:39 -03:00
committed by GitHub
17 changed files with 291 additions and 106 deletions

View File

@@ -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

View File

@@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Function with return type "int" cannot be used as getter for a property of type "String".

View File

@@ -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

View File

@@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Function with argument type "int" cannot be used as setter for a property of type "String".

View File

@@ -0,0 +1,9 @@
var _prop : int
# Inline getter returns int instead of String.
var prop : String:
get:
return _prop
func test():
pass

View File

@@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Cannot return value of type "int" because the function return type is "String".

View File

@@ -0,0 +1,9 @@
var _prop : int
# Inline setter assigns String to int.
var prop : String:
set(value):
_prop = value
func test():
pass

View File

@@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Cannot assign a value of type "String" to a target of type "int".

View File

@@ -0,0 +1,16 @@
var _prop = 1
var prop:
get = get_prop, set = set_prop
func get_prop():
return _prop
func set_prop(value):
_prop = value
func test():
print(prop)
prop = 2
print(prop)

View File

@@ -0,0 +1,3 @@
GDTEST_OK
1
2

View File

@@ -0,0 +1,46 @@
# Untyped inline property
var prop1:
get:
return prop1
set(value):
prop1 = value
# Typed inline property
var prop2 : int:
get:
return prop2
set(value):
prop2 = value
# Typed inline property with default value
var prop3 : int = 1:
get:
return prop3
set(value):
prop3 = value
# Typed inline property with backing variable
var _prop4 : int = 2
var prop4: int:
get:
return _prop4
set(value):
_prop4 = value
func test():
print(prop1)
print(prop2)
print(prop3)
print(prop4)
print()
prop1 = 1
prop2 = 2
prop3 = 3
prop4 = 4
print(prop1)
print(prop2)
print(prop3)
print(prop4)

View File

@@ -0,0 +1,10 @@
GDTEST_OK
null
0
1
2
1
2
3
4