Skip to content

Panic in getSignaturesOfType on a decorator's contextual type in JS APIΒ #64863

Open

Description

@auvred

πŸ”Ž Search Terms

getSignaturesOfType, panic

πŸ•— Version & Regression Information

Compiled on the latest main (5237fd4)

⏯ Playground Link

No response

πŸ’» Code

// panic.ts
import { API, SignatureKind } from '@typescript/typescript/sync';
import { isDecorator, type Node } from '@typescript/typescript/ast';
import { createFileSystem } from '@typescript/typescript/fs';

const file = '/repro.ts';
const api = new API();
const snapshot = api.createSnapshot({
    fileSystem: createFileSystem([[file, `
        class C { @((target, context) => target) get value(): number { return 1; } }
    `]]),
    createPrograms: [{ rootFiles: [file], compilerOptions: { noLib: true } }],
});
const program = snapshot.operation.createdPrograms[0]!;
const source = program.getSourceFile(file)!;
const checker = program.getProject().checker;

function visit(node: Node): void {
    if (isDecorator(node)) {
        const type = checker.getContextualType(node.expression)!;
        checker.getSignaturesOfType(type, SignatureKind.Call);
    }
    node.forEachChild(visit);
}
visit(source);

and then

node panic.ts

πŸ™ Actual behavior

> node panic.ts 
file:///Users/auvred/dev/github/typescript/packages/typescript/dist/api/syncChannel.js:248
                        throw new Error(this._msgPayload.toString("utf-8"));
                              ^

Error: panic: runtime error: invalid memory address or nil pointer dereference
goroutine 1 [running]:
runtime/debug.Stack()
        /Users/auvred/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.27.0.darwin-arm64/src/runtime/debug/stack.go:26 +0x64
github.com/microsoft/TypeScript/tsc/internal/ipc.(*SyncConn).handleRequest.func1()
        /Users/auvred/dev/github/typescript/tsc/internal/ipc/conn_sync.go:136 +0x50
panic({0x10363c468?, 0x10378e120?})
        /Users/auvred/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.27.0.darwin-arm64/src/runtime/panic.go:859 +0x120
github.com/microsoft/TypeScript/tsc/internal/ast.(*SourceFile).getDataCell[...](0x10295c840?, 0x55295c9e9588?)
        /Users/auvred/dev/github/typescript/tsc/internal/ast/ast.go:2342 +0x30
github.com/microsoft/TypeScript/tsc/internal/ast.(*SourceFile).GetOrComputeData[...](0x103393be0, 0x55295c9e95b8, 0x103758510?)
        /Users/auvred/dev/github/typescript/tsc/internal/ast/ast.go:2330 +0x2c
github.com/microsoft/TypeScript/tsc/internal/api/encoder.GetNodeIndexTable(...)
        /Users/auvred/dev/github/typescript/tsc/internal/api/encoder/encoder.go:417
github.com/microsoft/TypeScript/tsc/internal/api.nodeHandleFrom(0x55295c870360)
        /Users/auvred/dev/github/typescript/tsc/internal/api/session.go:296 +0x68
github.com/microsoft/TypeScript/tsc/internal/api.(*snapshotData).nodeHandleFrom(...)
        /Users/auvred/dev/github/typescript/tsc/internal/api/session.go:175
github.com/microsoft/TypeScript/tsc/internal/api.(*snapshotData).newSignatureResponse(0x55295cb0a008?, {0x55295c7e2e10?, 0x0?}, 0x55295c7bc5f0)
        /Users/auvred/dev/github/typescript/tsc/internal/api/session.go:505 +0x70
github.com/microsoft/TypeScript/tsc/internal/api.checkerSetup.newSignatureResponse(...)
        /Users/auvred/dev/github/typescript/tsc/internal/api/session.go:758
github.com/microsoft/TypeScript/tsc/internal/api.(*Session).handleGetSignaturesOfType(0x55295c7e3020?, {0x103755160?, 0x55295c9deac0?}, 0x55295c8751e0)
        /Users/auvred/dev/github/typescript/tsc/internal/api/session.go:2955 +0x16c
github.com/microsoft/TypeScript/tsc/internal/api.(*Session).HandleRequest(0x55295ca32000, {0x103755160?, 0x55295c9deac0?}, {0x55295c7e3020, 0x13}, {0x55295cb020a0?, 0x43?, 0x43?})
        /Users/auvred/dev/github/typescript/tsc/internal/api/session.go:997 +0x3418
github.com/microsoft/TypeScript/tsc/internal/ipc.(*SyncConn).handleRequest(0x55295c986d80, {0x103755160?, 0x55295c9deac0?}, 0x55295c7deaf0, 0x0)
        /Users/auvred/dev/github/typescript/tsc/internal/ipc/conn_sync.go:152 +0x454
github.com/microsoft/TypeScript/tsc/internal/ipc.(*SyncConn).Run(0x55295c986d80, {0x103755160, 0x55295c9deac0})
        /Users/auvred/dev/github/typescript/tsc/internal/ipc/conn_sync.go:79 +0x144
github.com/microsoft/TypeScript/tsc/internal/api.(*StdioServer).Run(0x55295c9e9d18, {0x103755160, 0x55295c9deac0})
        /Users/auvred/dev/github/typescript/tsc/internal/api/server.go:134 +0x598
main.runAPI({0x55295c942020, 0x3, 0x3})
        /Users/auvred/dev/github/typescript/tsc/cmd/tsc/api.go:83 +0x2b8
main.runMain()
        /Users/auvred/dev/github/typescript/tsc/cmd/tsc/main.go:26 +0xbc
main.main()
        /Users/auvred/dev/github/typescript/tsc/cmd/tsc/main.go:15 +0x1c

    at SyncRpcChannel.requestBytesSync (file:///Users/auvred/dev/github/typescript/packages/typescript/dist/api/syncChannel.js:248:31)
    at SyncRpcChannel.requestSync (file:///Users/auvred/dev/github/typescript/packages/typescript/dist/api/syncChannel.js:169:29)
    at Client.apiRequest (file:///Users/auvred/dev/github/typescript/packages/typescript/dist/api/sync/client.js:57:37)
    at ProjectObjectRegistry.<anonymous> (file:///Users/auvred/dev/github/typescript/packages/typescript/dist/api/sync/api.js:1547:39)
    at TypeObject.<anonymous> (file:///Users/auvred/dev/github/typescript/packages/typescript/dist/api/sync/api.js:4815:61)
    at Checker.<anonymous> (file:///Users/auvred/dev/github/typescript/packages/typescript/dist/api/sync/api.js:3088:55)
    at visit (file:///private/tmp/ts-api-decorator-panic/panic.ts:20:17)
    at RemoteNodeList.forEachNode (file:///Users/auvred/dev/github/typescript/packages/typescript/dist/api/node/node.generated.js:123:28)
    at RemoteNode.forEachChild (file:///Users/auvred/dev/github/typescript/packages/typescript/dist/api/node/node.generated.js:209:46)
    at visit (file:///private/tmp/ts-api-decorator-panic/panic.ts:22:10)

Node.js v24.18.0

πŸ™‚ Expected behavior

No panic

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