mirror of
https://github.com/godotengine/godot.git
synced 2026-01-03 18:11:19 +03:00
GDScript: Add warnings that are set to error by default
- Adds a list of default levels for all warning so they can be set individually. - Add warnings set by default to error for: - Using `get_node()` without `@onready`. - Using `@onready` together with `@export`. - Inferring a static type with a Variant value. - Overriding a native engine method. - Adjust how annotations to ignore warnings are treated so they also apply to method parameters. - Clean up a bit how ignored warnings are set. There were two sets but only one was actually being used. - Set all warnings to the `WARN` level for tests, so they they can be properly tested. - Fix enum types in native methods signatures being set to `int`. - Fix native enums being treated as Dictionary by mistake. - Make name of native enum types use the class they are defined in, not the direct super class of the script. This ensures they are always equal even when coming from different sources. - Fix error for signature mismatch that was only showing the first default argument as having a default. Now it shows for all.
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
extends Node
|
||||
|
||||
var add_node = do_add_node() # Hack to have one node on init and not fail at runtime.
|
||||
|
||||
var shorthand = $Node
|
||||
var with_self = self.get_node(^"Node")
|
||||
var without_self = get_node(^"Node")
|
||||
var with_cast = get_node(^"Node") as Node
|
||||
var shorthand_with_cast = $Node as Node
|
||||
|
||||
func test():
|
||||
print("warn")
|
||||
|
||||
func do_add_node():
|
||||
var node = Node.new()
|
||||
node.name = "Node"
|
||||
add_child(node)
|
||||
@@ -0,0 +1,22 @@
|
||||
GDTEST_OK
|
||||
>> WARNING
|
||||
>> Line: 5
|
||||
>> GET_NODE_DEFAULT_WITHOUT_ONREADY
|
||||
>> The default value is using "$" which won't return nodes in the scene tree before "_ready()" is called. Use the "@onready" annotation to solve this.
|
||||
>> WARNING
|
||||
>> Line: 6
|
||||
>> GET_NODE_DEFAULT_WITHOUT_ONREADY
|
||||
>> The default value is using "get_node()" which won't return nodes in the scene tree before "_ready()" is called. Use the "@onready" annotation to solve this.
|
||||
>> WARNING
|
||||
>> Line: 7
|
||||
>> GET_NODE_DEFAULT_WITHOUT_ONREADY
|
||||
>> The default value is using "get_node()" which won't return nodes in the scene tree before "_ready()" is called. Use the "@onready" annotation to solve this.
|
||||
>> WARNING
|
||||
>> Line: 8
|
||||
>> GET_NODE_DEFAULT_WITHOUT_ONREADY
|
||||
>> The default value is using "get_node()" which won't return nodes in the scene tree before "_ready()" is called. Use the "@onready" annotation to solve this.
|
||||
>> WARNING
|
||||
>> Line: 9
|
||||
>> GET_NODE_DEFAULT_WITHOUT_ONREADY
|
||||
>> The default value is using "$" which won't return nodes in the scene tree before "_ready()" is called. Use the "@onready" annotation to solve this.
|
||||
warn
|
||||
@@ -0,0 +1,6 @@
|
||||
func test():
|
||||
var inferred_with_variant := return_variant()
|
||||
print(inferred_with_variant)
|
||||
|
||||
func return_variant() -> Variant:
|
||||
return "warn"
|
||||
@@ -0,0 +1,6 @@
|
||||
GDTEST_OK
|
||||
>> WARNING
|
||||
>> Line: 2
|
||||
>> INFERENCE_ON_VARIANT
|
||||
>> The variable type is being inferred from a Variant value, so it will be typed as Variant.
|
||||
warn
|
||||
@@ -0,0 +1,6 @@
|
||||
extends Node
|
||||
|
||||
@onready @export var conflict = ""
|
||||
|
||||
func test():
|
||||
print("warn")
|
||||
@@ -0,0 +1,6 @@
|
||||
GDTEST_OK
|
||||
>> WARNING
|
||||
>> Line: 3
|
||||
>> ONREADY_WITH_EXPORT
|
||||
>> The "@onready" annotation will make the default value to be set after the "@export" takes effect and will override it.
|
||||
warn
|
||||
@@ -0,0 +1,5 @@
|
||||
func test():
|
||||
print("warn")
|
||||
|
||||
func get(_property: StringName) -> Variant:
|
||||
return null
|
||||
@@ -0,0 +1,6 @@
|
||||
GDTEST_OK
|
||||
>> WARNING
|
||||
>> Line: 4
|
||||
>> NATIVE_METHOD_OVERRIDE
|
||||
>> The method "get" overrides a method from native class "Object". This won't be called by the engine and may not work as expected.
|
||||
warn
|
||||
Reference in New Issue
Block a user