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

Default Node GDScript Template has Warnings/Errors with new Untyped Declaration Warning #82587

Closed
allenwp opened this issue Sep 30, 2023 · 8 comments · Fixed by #82801
Closed

Comments

@allenwp
Copy link
Contributor

allenwp commented Sep 30, 2023

Godot version

v4.2.dev5.official [e3e2528]

System information

Godot v4.2.dev5 - Windows 10.0.19045 - Vulkan (Mobile) - dedicated NVIDIA GeForce GTX 980 Ti (NVIDIA; 31.0.15.3699) - Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz (8 Threads)

Issue description

When creating a new GDScript with the default Node template, untyped declarations are used:

extends Node3D


# Called when the node enters the scene tree for the first time.
func _ready():
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	pass

I believe this is a bug because a template that has untyped declarations will cause warnings or errors if the new "Untyped Declaration" warning is enabled in the project settings. Additionally, the default template described in the documentation uses typed declarations and does not match the default template currently used by the editor.

Steps to reproduce

  1. Ensure that no Editor-defined templates exist
  2. Create a new project
  3. Under Project Settings (Advanced Settings) -> Debug -> GDScript -> Untyped Declaration: Set to Warn or Error
  4. Create a new GDScript through the FileSystem panel or by choosing Attach Script on a new scene's root node
  5. Note that the new GDScript uses untyped declarations and does not match the documentation

image
image

Minimal reproduction project

N/A

@dalexeev
Copy link
Member

Make sure the text_editor/completion/add_type_hints editor setting is enabled:

@Maran23
Copy link
Contributor

Maran23 commented Sep 30, 2023

Make sure the text_editor/completion/add_type_hints editor setting is enabled:

Maybe it makes sense to have this enabled by default now?

@dalexeev
Copy link
Member

Maybe it makes sense to have this enabled by default now?

Note that the UNTYPED_DECLARATION, INFERRED_DECLARATION, and UNSAFE_* warnings are disabled by default. We assume that if users want static typing, they will enable the desired settings themselves. The documentation and demo projects also use untyped GDScript by default, although there is a suggestion to use static typing in demo projects.

@allenwp
Copy link
Contributor Author

allenwp commented Sep 30, 2023

Make sure the text_editor/completion/add_type_hints editor setting is enabled:

Confirmed that setting "Add Type Hints" to On changes the default template to use typed declarations.

But I think there is still a usability issue that exists here... When a project has the new Untyped Declaration set to Warn or Error it is not obvious to the user that they need to change additional editor settings to play nice with this project setting.

I found out about the Untyped Declaration warning when searching for a way to disable dynamic typing in GDScript, but I had no idea that I might need to make additional editor settings changes to make the script editor play nicely with my new project settings.

Additionally, if a project is shared between multiple developers, all developers may not intuitively understand that they need to adjust their editor settings to play nice with the project settings.

I think it would be good to brainstorm a way to make this a bit more intuitive to new users, either in this issue thread or maybe in a new proposal...

@allenwp
Copy link
Contributor Author

allenwp commented Sep 30, 2023

Here are a couple of options that could address the usability issue relating to Untyped Declaration warnings/errors and Add Type Hints:

  1. Type Hints are always on when Untyped Declaration is set to warn or error in the current project. The "Add Type Hints" editor setting is ignored and has a note saying that the setting is only respected when Untyped Declaration is set to ignore in the current project settings.
  2. Type Hints default is changed to on. (This sounds like a bad idea because it conflicts with the default dynamic typing behaviour of Godot?)
  3. The default Node GDScript template is updated to always use type declaration, similar to how it is currently shown in the documentation. (This sounds like a bad idea because it conflicts with the default dynamic typing behaviour of Godot?)
  4. The Untyped Declaration documentation/tooltip is updated to say something like "When changing this to Warn or Error, consider turning on the Add Type Hints editor setting."

Unless option 3 is implemented, the documentation should be updated to match the default Godot behaviour.

I think, at the very least, option 4 should be implemented. This way when the new Untyped Declaration project setting is officially launched, users will know how best to configure their Editor Settings when using it.

@allenwp
Copy link
Contributor Author

allenwp commented Oct 4, 2023

Regarding the default template described in the documentation, I've made a separate docs issue and PR.

@allenwp
Copy link
Contributor Author

allenwp commented Oct 4, 2023

Edit: Mistakenly commented on the wrong issue

@allenwp allenwp closed this as completed Oct 4, 2023
@allenwp
Copy link
Contributor Author

allenwp commented Oct 4, 2023

Whoops, accidentally commented on the wrong issue.

@allenwp allenwp reopened this Oct 4, 2023
@akien-mga akien-mga added this to the 4.2 milestone Oct 30, 2023
orianbsilva pushed a commit to orianbsilva/godot that referenced this issue Nov 1, 2023
…on warning

Fixes godotengine#82587 by improving usability of the untyped_declaration warning. This adds a note to the documentation that recommends turning on EditorSettings.text_editor/completion/add_type_hints when the untyped declaration warning is set to warn or error.

Co-authored-by: Yuri Sizov <[email protected]>
GuybrushThreepwood-GitHub pushed a commit to GuybrushThreepwood-GitHub/godot that referenced this issue Jan 27, 2024
…on warning

Fixes godotengine#82587 by improving usability of the untyped_declaration warning. This adds a note to the documentation that recommends turning on EditorSettings.text_editor/completion/add_type_hints when the untyped declaration warning is set to warn or error.

Co-authored-by: Yuri Sizov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants