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
Cannot call own functions inside a match pattern #18174
Comments
If you use math functions with literals, it'll be reduced to a constant by the parser, that's probably why it's allowed. |
As @vnen said, constant expressions are reduced by the parser, but regular function calls can't. Also if you "match with a function call" then that function might have side effects, that's bad practise in general. In most languages that have pattern matching you can only match on constant expressions, so this is actually expected. One of the first iterations of the match statement allowed this, but as I said, as soon as you introduce side effect and all that, it becomes very messy, so I suggest we keep it as it is |
I see. It would be cool to see something like C++'s |
Feature and improvement proposals for the Godot Engine are now being discussed and reviewed in a dedicated Godot Improvement Proposals (GIP) (godotengine/godot-proposals) issue tracker. The GIP tracker has a detailed issue template designed so that proposals include all the relevant information to start a productive discussion and help the community assess the validity of the proposal for the engine. The main (godotengine/godot) tracker is now solely dedicated to bug reports and Pull Requests, enabling contributors to have a better focus on bug fixing work. Therefore, we are now closing all older feature proposals on the main issue tracker. If you are interested in this feature proposal, please open a new proposal on the GIP tracker following the given issue template (after checking that it doesn't exist already). Be sure to reference this closed issue if it includes any relevant discussion (which you are also encouraged to summarize in the new proposal). Thanks in advance! |
Godot version:
3.0.2 Mono
OS/device including version:
KDE Neon
Issue description:
If you call a function you defined yourself inside of a pattern in a match clause, you get the following parser error:
built-in:8 - Parse Error: Invalid operator in pattern. Only index (
A.B) is allowed
Additionally, most other methods don't seem to work either. But you can use math functions like
pow
,abs
, etc. It could be that only "global" functions work inside a match clause?Steps to reproduce:
The text was updated successfully, but these errors were encountered: