diff options
author | George Marques <george@gmarqu.es> | 2021-10-06 11:39:19 -0300 |
---|---|---|
committer | George Marques <george@gmarqu.es> | 2021-10-06 11:42:19 -0300 |
commit | 6bdb28f5e41d5e3eef866fde161fb5a259a6a11b (patch) | |
tree | 3cd7e3beeaffbc5d886e66d2ac43894d47c8c571 /modules/gdscript/tests/scripts/analyzer | |
parent | d6c799006ad9305fc4fca1574aff148e2529f8b6 (diff) |
GDScript: Avoid hard errors on inferred types
Since inference isn't always correct, they are now treated as unsafe
instead of errors.
This also removes inferred type when a variable is reassigned. Since
it's not aware of branching, the types might become invalid in a later
context.
Diffstat (limited to 'modules/gdscript/tests/scripts/analyzer')
4 files changed, 29 insertions, 0 deletions
diff --git a/modules/gdscript/tests/scripts/analyzer/features/class_inference_is_weak.gd b/modules/gdscript/tests/scripts/analyzer/features/class_inference_is_weak.gd new file mode 100644 index 0000000000..630b20c282 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/class_inference_is_weak.gd @@ -0,0 +1,11 @@ +# https://github.com/godotengine/godot/issues/43503 + +var test_var = null + + +func test(): + print(test_var.x) + + +func _init(): + test_var = Vector3() diff --git a/modules/gdscript/tests/scripts/analyzer/features/class_inference_is_weak.out b/modules/gdscript/tests/scripts/analyzer/features/class_inference_is_weak.out new file mode 100644 index 0000000000..94e2ec2af8 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/class_inference_is_weak.out @@ -0,0 +1,2 @@ +GDTEST_OK +0 diff --git a/modules/gdscript/tests/scripts/analyzer/features/local_inference_is_weak.gd b/modules/gdscript/tests/scripts/analyzer/features/local_inference_is_weak.gd new file mode 100644 index 0000000000..b3784dffa3 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/local_inference_is_weak.gd @@ -0,0 +1,14 @@ +# https://github.com/godotengine/godot/issues/41064 +var x = true + +func test(): + var int_var: int = 0 + var dyn_var = 2 + + if x: + dyn_var = 5 + else: + dyn_var = Node.new() + + int_var = dyn_var + print(int_var) diff --git a/modules/gdscript/tests/scripts/analyzer/features/local_inference_is_weak.out b/modules/gdscript/tests/scripts/analyzer/features/local_inference_is_weak.out new file mode 100644 index 0000000000..952029f665 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/local_inference_is_weak.out @@ -0,0 +1,2 @@ +GDTEST_OK +5 |