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

Autocomplete doesn't show for type-hinted variables that are locally assigned without the 'as' keyword #87469

Closed
GodotIsDaBomb opened this issue Jan 22, 2024 · 1 comment

Comments

@GodotIsDaBomb
Copy link

Tested versions

-Reproduceable in 4.2.1 and 4.3-dev2, both on Windows and Linux. I believe this has been present since at least 4.1, never tried in 4.0

System information

Godot v4.3.dev2 - Windows 10.0.19045 - Vulkan (Forward+) - integrated Intel(R) HD Graphics 530 (Intel Corporation; 30.0.101.1340) - Intel(R) Core(TM) i5-6600 CPU @ 3.30GHz (4 Threads)

Issue description

If you use type hints to assign a variable say from get_parent() or somewhere other than the class members it won't work

func _process(delta):
	var parent : MyCustomClass = get_parent()
	var global_obj_of_import : AnotherCustomClass = Globals.a_member

func a_function():
	for child in get_children():
		var custom_class : MyCustomClass = child

This requires the use of the 'as' keyword. I understand that the code doesn't check for the type and so at runtime it doesn't "know" that the type hint is correct, meaning the variable will be null if it isn't that type. The thing is, when coding, if the code specifies a type hint of a variable, it should show the relevent autocomplete. I should be even be able to swap the type hint to something completely wrong but get the code complete for that typehint.

Steps to reproduce

  1. Create a script that makes use of the 'class_name' keyword
  2. Add some functions or member variables you expect it to have
  3. Assign something to a local variable from get_parent(), get_children() in a loop, or an Autoload using the class_name in the type hint (as described in the issue description)

Minimal reproduction project (MRP)

autocomplete.zip

@AThousandShips
Copy link
Member

AThousandShips commented Jan 22, 2024

Thank you for reporting, closing as a duplicate of:

Should be fixed by:

@AThousandShips AThousandShips marked this as a duplicate of #86871 Jan 22, 2024
@AThousandShips AThousandShips closed this as not planned Won't fix, can't repro, duplicate, stale Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants