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

Overwriten methods should default to the same return type as the super class's method #811

Open
DrAlta opened this issue May 8, 2020 · 1 comment

Comments

@DrAlta
Copy link

DrAlta commented May 8, 2020

Describe the project you are working on:
Making small programs to learn GDscript

Describe the problem or limitation you are having in your project:
I couldn't figure out why I couldn't change how my object was printed. I had forgotten to type return before the string.

Describe the feature / enhancement and how it helps to overcome the problem or limitation:
If _to_string had a default return type I would have cough the error immediately.

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
_to_string should give an error if it doesn't return a string. I assume it could use the mechanisms that are used to catch mixmatch returns with declared return types.
If this enhancement will not be used often, can it be worked around with a few lines of script?:
Not that I know of.
Is there a reason why this should be core and not an add-on in the asset library?:
It's most useful to new programmers that would have the experience to look for and install an addon.

@DrAlta DrAlta changed the title _to_string should give an error if it don't return a string Overwriten method should default to the same return type as the super class's method May 9, 2020
@DrAlta DrAlta changed the title Overwriten method should default to the same return type as the super class's method Overwriten methods should default to the same return type as the super class's method May 9, 2020
@Kequc
Copy link

Kequc commented May 10, 2020

Types are optional in gdscript, it's entirely possible you wanted to return a different type from the overridden function. From what I understand type checking doesn't go beyond the currently opened file right now. Adding a return type to the function definition would definitely warn you if you weren't returning.

A similar annoyance I've noticed though, is that if you extend a class that has an _init function you have to explicitly define the _init function again. It would be nice if it would use the _init function in the parent class.

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.

3 participants