JavaClassWrapper: Give additional error when trying to call non-static method directly on the class #102494
+3
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #102019
I'm not sure this is the right fix.
JavaClass
is still returningCALL_ERROR_INSTANCE_IS_NULL
when a developer tries to call a non-static method directly on the class, which means the GDScript VM will still show its not-very-helpful message. But this adds an additional error giving more helpful information.I went this way because the other
CALL_ERROR_*
values aren't any more appropriate to this situation. We could doCALL_ERROR_INVALID_METHOD
, but that has the same confusion as on the issue, where the developer listed the methods, and saw that this one exists, but they can't call it on the class. And looking at other places where Godot usesCALL_ERROR_INSTANCE_IS_NULL
, it really seems like the most appropriate error.Another option would be to modify the GDScript VM's message to say something about non-static methods, but that would be kinda weird because GDScript itself can detect that you're calling a non-static method in the parser, before it even gets to the VM, so this can't come up with pure GDScript or native classes. So, I don't know that it makes sense to change that?
I'd love feedback on if doing it this way makes sense, or if we should do one of the alternatives.