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

Static GDScript Typing Variant #26228

Closed
razcore-rad opened this issue Feb 24, 2019 · 6 comments
Closed

Static GDScript Typing Variant #26228

razcore-rad opened this issue Feb 24, 2019 · 6 comments

Comments

@razcore-rad
Copy link
Contributor

On latest static GDScript typing, there are some virtual functions that return Variant, and there's no way to replicate that in GDScript. What comes to mind is Object._get function for example. There's no way to say func _get(property: String) -> Variant in GDScript, "best" implementation so far is to ignore return value: func _get(property: String).

We need a mechanism to return not just Object & built-in types but Variant as well or maybe there are other options out there too?

@neikeq
Copy link
Contributor

neikeq commented Feb 24, 2019

Ignoring the return type is effectively the same as returning Variant.

@razcore-rad
Copy link
Contributor Author

razcore-rad commented Feb 24, 2019

Yeah but that doesn't fix the problem. What do you do with the other virtual methods that expect Variant as parameter? like _set, I mean sure, you can do the same, define it with no typing hints: func _set(property: String, val) -> void, but I guess I prefer having a generic type hint like Variant exposed to make it explicit

@eon-s
Copy link
Contributor

eon-s commented Feb 24, 2019

Variant is also present on the class reference as a core type, but is not exposed to GDScript.

@Calinou
Copy link
Member

Calinou commented Feb 25, 2019

I like the idea of a generic type hint too (similar to TypeScript's any type, whose usage can be enforced using the noImplicitAny flag). In a static typing-first workflow, this makes sure every usage of dynamic typing is carefully considered.

We could then have a GDScript warning (disabled by default) that would be emitted whenever type hints aren't specified somewhere.

@Calinou
Copy link
Member

Calinou commented Apr 7, 2020

Closing in favor of godotengine/godot-proposals#605, as feature proposals are now tracked on the Godot proposals repository.

@Calinou
Copy link
Member

Calinou commented Sep 18, 2020

For anyone stumbling upon this issue from a web search, this is now supported in master since the new GDScript was merged:

image

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

4 participants