Skip to content

Clarify type-safety of as #10781

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

Merged
merged 4 commits into from
Apr 6, 2025
Merged

Clarify type-safety of as #10781

merged 4 commits into from
Apr 6, 2025

Conversation

Lexyth
Copy link
Contributor

@Lexyth Lexyth commented Mar 18, 2025

Changed the statement about the as keyword's type-safety to clarify that it is less type-safe than type hints.

Changed the statement about the as keyword's type-safety to clarify that it is less type-safe than type hints.
@dalexeev
Copy link
Member

I find your correction useful in a practical sense, but imprecise in terminology.

Type safety means a guarantee that you won't get a type error at runtime. The as operator is more type safe, but also more error-prone.

The problem is that objects are nullable, null safety is not guaranteed by the current type system for objects.

@dalexeev dalexeev added enhancement discussion topic:gdscript area:manual Issues and PRs related to the Manual/Tutorials section of the documentation labels Mar 20, 2025
Changed the statement about the "as" keyword to clarify that it affects null-safety, not type-safety.
@Lexyth
Copy link
Contributor Author

Lexyth commented Mar 23, 2025

I find your correction useful in a practical sense, but imprecise in terminology.

Type safety means a guarantee that you won't get a type error at runtime. The as operator is more type safe, but also more error-prone.

The problem is that objects are nullable, null safety is not guaranteed by the current type system for objects.

I agree. I have edited it to clarify that: "[...] more :ref:type-safe<doc_gdscript_static_typing_safe_lines> than type hints, but also less null-safe [...]"

Used code-block format for "null" keyword.

Co-authored-by: Danil Alexeev <[email protected]>
Reduced the line length to make it more readable.

Co-authored-by: A Thousand Ships <[email protected]>
Copy link
Contributor

@skyace65 skyace65 left a comment

Choose a reason for hiding this comment

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

Checked for grammar

@skyace65 skyace65 merged commit 1335f38 into godotengine:master Apr 6, 2025
1 of 2 checks passed
@skyace65
Copy link
Contributor

skyace65 commented Apr 6, 2025

Thanks!

@Lexyth Lexyth deleted the patch-3 branch April 9, 2025 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:manual Issues and PRs related to the Manual/Tutorials section of the documentation discussion enhancement topic:gdscript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants