Skip to content

Add GDScript warning pages #10635

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

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a7d10a2
Add GDScript warning pages, with content for `GET_NODE_DEFAULT_WITHOU…
Meorge Feb 6, 2025
bac9723
Apply suggestions from code review
Meorge Feb 7, 2025
20a444e
Remove inline code formatting from page titles
Meorge Feb 7, 2025
eac8c53
Improvements to `GET_NODE_DEFAULT_WITHOUT_ONREADY` prototype page
Meorge Feb 7, 2025
524ab62
Add warning messages that display in editor (placeholder %s kept)
Meorge Feb 7, 2025
d0bdcc7
Wrote for `ASSERT_ALWAYS_FALSE` and ASSERT_ALWAYS_TRUE`
Meorge Feb 12, 2025
1d179a1
Improve documentation for `ASSERT_ALWAYS_FALSE`
Meorge Feb 12, 2025
375646e
Update tutorials/scripting/gdscript/warnings/ASSERT_ALWAYS_FALSE.rst
Meorge Feb 13, 2025
a2a6829
Add default warning levels to pages
Meorge Mar 24, 2025
28f1c48
Update a few pages to use placeholder variable names
Meorge Mar 27, 2025
1375d4f
Use `snake_case` for page names
Meorge Mar 27, 2025
fde83c4
Replace `%s` in warnings with example strings
Meorge Mar 28, 2025
4956a9e
Remove unused warnings
Meorge Mar 28, 2025
957c224
Improve example message for `INFERRED_DECLARATION`
Meorge Mar 28, 2025
02d7162
Change `DEPRECATED_KEYWORD` page to clarify that the warning should n…
Meorge Mar 30, 2025
e98a2c2
Add links to ProjectSettings's configuration variables for warning le…
Meorge Mar 30, 2025
dae7b58
Fix typo
Meorge Apr 1, 2025
5ae07d2
Add doc for CONFUSABLE_IDENTIFIER
Meorge Apr 27, 2025
40b1dc8
Add doc for EMPTY_FILE
Meorge May 8, 2025
9b96186
Add doc for ENUM_VARIABLE_WITHOUT_DEFAULT
Meorge May 8, 2025
062a349
Add doc for INFERRED_DECLARATION
Meorge May 8, 2025
9ace5a4
Add doc for INFERENCE_ON_VARIANT
Meorge May 8, 2025
e52297a
Add docs for INT_AS_ENUM_WITHOUT_CAST, INT_AS_ENUM_WITHOUT_MATCH, and…
Meorge May 9, 2025
e8d9d5c
Add doc for NATIVE_METHOD_OVERRIDE
Meorge May 9, 2025
2169818
Add doc for RETURN_VALUE_DISCARDED
Meorge May 9, 2025
23fd72b
Add doc for SHADOWED_GLOBAL_IDENTIFIER
Meorge May 12, 2025
e8cb120
Add doc for SHADOWED_VARIABLE_BASE_CLASS
Meorge May 12, 2025
9b55aa1
Add doc for SHADOWED_VARIABLE
Meorge May 12, 2025
5b7843c
Make formatting fixes
Meorge May 12, 2025
0a5913d
Add doc for STANDALONE_EXPRESSION
Meorge May 13, 2025
ef9c5cd
Add doc for STANDALONE_TERNARY
Meorge May 13, 2025
6d56e74
Add doc for STATIC_CALLED_ON_INSTANCE
Meorge May 13, 2025
4e73a26
Add comments to some GDScript snippets
Meorge May 13, 2025
6ed918b
Add doc for `UNASSIGNED_VARIABLE_OP_ASSIGN`
Meorge May 15, 2025
cdfdde6
Add doc for UNASSIGNED_VARIABLE
Meorge May 15, 2025
944931f
Add doc for UNREACHABLE_CODE
Meorge May 15, 2025
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
34 changes: 23 additions & 11 deletions tutorials/scripting/gdscript/warnings/ASSERT_ALWAYS_FALSE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,39 @@ The warning message is:
When this warning occurs
------------------------

The :ref:`assert() <class_@GDScript_method_assert>` keyword can be used to ensure that a given condition is met before allowing code execution to continue. If the first argument passed to it evaluates to ``true``, the rest of the function will run as expected; if it is ``false``, then the project will stop.
The :ref:`assert() <class_@GDScript_method_assert>` keyword can be used to ensure that a given condition is met before allowing code execution to continue. If the first argument passed to it is truthy, the rest of the function will run as expected; if it is falsy, then the project will stop.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if we defined truthy/falsy somewhere else in the GDScript docs that we could link to, see also #4408

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. In general I'm nervous about even using the terms "truthy" and "falsy" right now, because neither of them currently appear in the docs at all from what I can see (searching either of them on the online docs turns up no results).

Copy link
Member

@Mickeon Mickeon Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to do this in Variant's own class reference in godotengine/godot#95487 but I haven't had the time to retouch it considerably.

Note that a lot of Variant types describe what happens in "a boolean context" in their respective descriptions.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I may use that wording instead to remain consistent!


If ``assert()`` is passed an expression that is guaranteed to be ``false``, then the ``assert()`` call will always stop the project.
If ``assert()`` is passed something guaranteed to be falsy, then the ``assert()`` call will always stop the project.

.. code-block::

# The boolean false will always be false, so this assert will always stop
# the program.
assert(false, "False is false")
# Zero always evaluates to false.
assert(0, "Zero is falsy")

# Likewise, 5 will never be 6, so this assert will always stop the program.
assert(5 == 6, "5 isn't equal to 6")
# Likewise, an empty string always evaluates to false.
assert("", "An empty string is falsy")

# This line of code won't be executed in debug builds because the editor
# will have stopped at the assert calls above.
print("Hello, world!")
.. note::

Godot will *not* raise this warning if a literal falsy boolean is passed:

.. code-block::

# Despite false being passed, this won't raise ASSERT_ALWAYS_FALSE.
assert(false, "False is false")

# This evaluates to a boolean which is false, so it also won't raise
# the warning.
assert(3 == 4, "3 isn't equal to 4")

This is because ``assert(false)`` calls are often used in development to forcibly halt program execution and avoid strange errors later on.

See `issue #58087 <https://github.com/godotengine/godot/issues/58087>`_ for more information.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
See `issue #58087 <https://github.com/godotengine/godot/issues/58087>`_ for more information.
See `GH-58087 <https://github.com/godotengine/godot/issues/58087>`_ for more information.

Usually it's styled like this.

Linking to the original issue/PR from the docs seems like an antipattern though, usually we would rewrite the relevant content of the issue/PR into a form suitable for the manual. I'm not wholly against linking though

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of linking the issue/PR, similar to how one might paraphrase a primary source in an essay and then provide a citation to the primary source itself, so the reader can look at it themselves if they so wish. But the reasoning provided in the issue might be general enough that it doesn't "need" a citation, and it could also make it unclear when it's appropriate to link to GitHub, resulting in the docs becoming more cluttered.


How to fix this warning
-----------------------

Assuming you want code following the ``assert()`` to run, remove it from your code. If you do want code execution to stop at that point, :ref:`consider using breakpoints instead <doc_debugger_tools_and_options>`.
Assuming you want code following the ``assert()`` to run, remove it from your code. If you do want code execution to stop at that point, replace the condition with ``false``, or :ref:`consider using breakpoints instead <doc_debugger_tools_and_options>`.