Skip to content

Panic during declaration emit with stripInternal on parenthesized or wrapped internal type #65623

Open

Description

🔎 Search Terms

stripInternal, parenthesized type, panic, nil pointer dereference, declaration emit, ParenthesizedType

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about stripInternal
  • Tested on TypeScript main (Version 7.1.0-dev)

⏯ Playground Link

No response

💻 Code

interface Foo {}

// Case 1: Type alias with parenthesized internal type
export type T = (
    /** @internal */
    Foo
);

// Case 2: Variable type annotation with parenthesized internal type
export const x: (
    /** @internal */
    Foo
) = {} as any;

// Case 3: Type operator and array wrapping parenthesized internal type
export type T2 = readonly (
    /** @internal */
    Foo
)[];

🙁 Actual behavior

Running tsc -d --stripInternal crashes the compiler with a runtime panic (nil pointer dereference):

panic: runtime error: invalid memory address or nil pointer dereference [signal 0xc0000005 code=0x0 addr=0x0 pc=...]

goroutine ... [running]: github.com/microsoft/TypeScript/tsc/internal/ast.GetTypeNodePrecedence(...) tsc/internal/ast/precedence.go:656 github.com/microsoft/TypeScript/tsc/internal/printer.(*Printer).emitTypeNode(...) tsc/internal/printer/printer.go:2298 github.com/microsoft/TypeScript/tsc/internal/printer.(*Printer).emitParenthesizedType(...) tsc/internal/printer/printer.go:2114 github.com/microsoft/TypeScript/tsc/internal/printer.(*Printer).emitTypeAliasDeclaration(...) tsc/internal/printer/printer.go:3809

Cause:
When --stripInternal elides an @internal type wrapped in a parenthesized type, VisitEachChild calls UpdateParenthesizedTypeNode(input, nil), constructing a node with an inner nil pointer. The printer attempts to inspect node.Type.Kind for operator precedence and dereferences nil.

🙂 Expected behavior

The compiler should emit declarations without crashing:

  • T should fall back to export type T = any; (matching the behavior of bare export type T = /** @internal */ Foo;).
  • x should emit export declare const x;.
  • T2 should fall back to export type T2 = any;.

Additional information about the issue

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions