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

Activity

changed the title [-]Optional chaining On methods[/-] [+]Optional Chaining on Function Calls / Methods[/+] on Dec 18, 2024
self-assigned this
on Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @antonmedv@xiaoas

      Issue actions

        Optional Chaining on Function Calls / Methods · Issue #741 · expr-lang/expr