Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add info about untyped_declaration and inferred_declaration warnings. #8137

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions tutorials/scripting/gdscript/static_typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,50 @@ You can't specify the type of individual members in an array:

var enemies: Array = [$Goblin: Enemy, $Zombie: Enemy]

Enforce static typing in a project
----------------------------------

By setting ``debug/gdscript/warnings/untyped_declaration`` to ``Warn`` or
``Error``, you can receive a warning or error respectively when the analyzer
can't infer the type. For example,

::

extends Node

var untyped = 23 # untyped_declaration warning emitted.
var typed: int = 23 # no warning emitted.
var inferred := 23 # inferred as int, no warning

func _ready(): # untyped_declaration warning emitted.
pass

func _process(delta: float) -> void: # no warning emitted.
for i in range(4): # no warning, i has an inferred type of int.
print(i)

Additionally, by setting ``debug/gdscript/warnings/inferred_declaration`` to
``Warn`` or ``Error``, you can receive a warning if a declaration is of an
inferred type, i.e. ``:=``. It is recommended to only use this warning along
with ``debug/gdscript/warnings/untyped_declaration`` as using the warning
alone will only warn when the type is inferred, not undeclared.

::

extends Node

var untyped = 23 # untyped_declaration warning emitted.
var typed: int = 23 # no warning emitted.
var inferred := 23 # inferred_declaration warning emitted.

func _ready(): # untyped_declaration warning emitted.
pass

func _process(delta: float) -> void: # no warning emitted.
for i in range(4): # inferred_declaration warning emitted.
print(i)


Summary
-------

Expand Down