-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
Implement abstract methods in GDScript #82987
base: master
Are you sure you want to change the base?
Implement abstract methods in GDScript #82987
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to check that super()
and super.method()
do not refer to an abstract method.
if (!p_function->get_datatype().is_hard_type() && p_function->body->get_datatype().is_set()) { | ||
// Use the suite inferred type if return isn't explicitly set. | ||
p_function->set_datatype(p_function->body->get_datatype()); | ||
} else if (p_function->get_datatype().is_hard_type() && (p_function->get_datatype().kind != GDScriptParser::DataType::BUILTIN || p_function->get_datatype().builtin_type != Variant::NIL)) { | ||
if (!p_function->body->has_return && (p_is_lambda || p_function->identifier->name != GDScriptLanguage::get_singleton()->strings._init)) { | ||
if (!p_function->is_abstract && !p_function->body->has_return && (p_is_lambda || p_function->identifier->name != GDScriptLanguage::get_singleton()->strings._init)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to check if there is code that relies on has_return
and if this could lead to negative effects. I remember exactly that this is used in the compiler and in DocGen. Alternatively, we could add a fake return
for abstract non-void
functions, but this is an undesirable hack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would one check for this? I'm still learning about the GDScript codebase :p
It should also be prohibited to mark constructor ( |
7c06997
to
4d2d2e8
Compare
I resolved most of the changes from you @dalexeev . I will need some help with the remaining steps you mentioned:
|
192e0fd
to
bd03c7a
Compare
Co-authored-by: Danil Alexeev <[email protected]>
bd03c7a
to
c380cc2
Compare
It's been a while since anything was said about this PR... |
This PR depends on #67777 Once it's merged, I will probably come back to it and update the PR to accommodate any changes made since my last push. |
I think since the required pr uses keywords to declare abstract classes, you should also use keywords to declare abstract functions |
This was not originally the decision, so this simply follows the original design, for more details see #67777 (comment), but see also #82987 (comment), this is waiting on another PR |
Yes, so shouldn't this PR also be changed? |
Yes, but I will work on it once the abstract classes PR gets merged 😅 |
It should, but it depends on the desire and availability of the author; we cannot require volunteers to work. It also makes sense to wait until the base PR is at least reviewed and approved, so as not to ask the author of this PR to do extra work. |
Ah, sorry for my phrasing, I was just asking if it should, not that it needs to. |
Depends on #67777 .
This PR allows the
@abstract
annotation defined in the PR above to be used on methods. Abstract methods have the following properties:They must exist inside an abstract class:
They cannot have an implementation
They MUST be implemented by subclasses
Please test this and let me know your thoughts!
Below is a simple example project to use in testing:
test_project_abstract_methods.zip