Skip to content

optional call obj.fn?.(...) throws when fn is undefined (should short-circuit to undefined) #830

Description

@proggeramlug

Surfaced by the new feature-matrix probe test-files/test_feat_optional_chaining.ts (added under #801).

Repro

interface User { greet?: (who: string) => string }
const sparse: User = { id: 2 } as User;
console.log("sparse.greet?.('bob'):", sparse.greet?.("bob"));

Expected (Node)

sparse.greet?.('bob'): undefined

Actual (Perry v0.5.914)

TypeError: greet is not a function
    at <anonymous>

The optional-call form obj.fn?.(...) must short-circuit to undefined when obj.fn is null/undefined — it must not invoke the call at all. Perry is currently evaluating the call site regardless of the ?. short-circuit.

Property-access optional chain works

The plain ?.email/?.phone?.work forms in the same test pass — only the optional-CALL form is broken.

Impact

This blocks ~all real-world TS code that uses optional method invocation (event-handler patterns, optional callbacks).

Part of #793 (axis 1 — TypeScript language). Surfaced by the #801 feature matrix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed defect or regressionparityCompatibility gap with Node.js, ECMAScript, or the supported ecosystem

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions