Skip to content

Optional Chaining on Function Calls / Methods #741

Open
@xiaoas

Description

@xiaoas

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions