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

[BUG] Safe navigation for function calls throws a compile error #11094

Closed
EliteMasterEric opened this issue Apr 7, 2023 · 5 comments
Closed

Comments

@EliteMasterEric
Copy link
Contributor

ERROR source/funkin/play/cutscene/dialogue/DialogueBox.hx:157: characters 29-30
157 | typingCompleteCallback?.();
| ^
| Unexpected (

The accepted proposal for safe navigation provides for optional chaining to be used on function as well; if a function with a value of null would be called with ?.(), it will not be called, and return null instead if a return value is expected.

A cursory review of #10561 finds that this functionality was not implemented in the test cases. It may be that this was never properly implemented.

@EliteMasterEric
Copy link
Contributor Author

Just learned the feature was left unimplemented, see here:

https://youtu.be/lkpoTcHKjSE?t=454

@alexeychikk
Copy link

Is safe navigation for call expression going to be implemented at all?

@T1mL3arn
Copy link
Contributor

T1mL3arn commented Jan 3, 2024

Maybe reopen the issue to be sort of a feature request? We have now obj?.prop, so would be nice to have obj.foo?.() instead of

if (obj.foo != null)
  obj.foo();

@EliteMasterEric
Copy link
Contributor Author

Maybe reopen the issue to be sort of a feature request? We have now obj?.prop, so would be nice to have obj.foo?.() instead of

if (obj.foo != null)
  obj.foo();

See the explanation in the video. The main argument against ?.() is that the behavior of side effects is unclear, and in most user code, it is much rarer for functions to be null as opposed to objects (you would have to be working with anonymous structures or functions using the dynamic keyword).

@EliteMasterEric
Copy link
Contributor Author

I made HaxeFoundation/haxe-evolution#114 as a home for discussion around ?.[] and ?.(). This issue can stay closed as the syntax is unimplemented, not bugged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants