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

Optional Chaining on Function Calls / Methods #741

Open
xiaoas opened this issue Dec 18, 2024 · 0 comments
Open

Optional Chaining on Function Calls / Methods #741

xiaoas opened this issue Dec 18, 2024 · 0 comments
Assignees
Labels

Comments

@xiaoas
Copy link

xiaoas commented Dec 18, 2024

Currently, Optional chaining on Object fields work well:

MyObj?.Field1 ?? "default"

However, one cannot make an optional call to a method on an object:

// this panics when MyObj is nil
MyObj?.Method1() ?? "default"
// this does not compile
MyObj?.Method1?.() ?? "default"

So one is forced to write this, which works but is more verbose. Especially when MyObj is actually a long expression:

MyObj != nil ? MyObj.Method1() : "default"

Expected Behavior

?.() should be a valid optional function call syntax

@xiaoas xiaoas changed the title Optional chaining On methods Optional Chaining on Function Calls / Methods Dec 18, 2024
@antonmedv antonmedv self-assigned this Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants