Skip to content

Quick fix crash when promoting type-only import to value and existing type import precedes new value import #2559

@DanielRosenwasser

Description

@DanielRosenwasser

foo.mts:

import type {
    AAA,
    BBB,
} from "./bar.mjs";

let x: AAA = new /*$*/BBB()

bar.mts:

export interface AAA {}
export class BBB {}

At /*$*/, request a quick fix.

[error] panic handling request textDocument/codeAction: runtime error: invalid memory address or nil pointer dereference
goroutine 4401 [running]:
runtime/debug.Stack()
	runtime/debug/stack.go:26 +0x64
github.com/microsoft/typescript-go/internal/lsp.(*Server).recover(0x4000180e08, {0x7ff78e20ac88, 0x40093e0d80}, 0x400932c120)
	github.com/microsoft/typescript-go/internal/lsp/server.go:773 +0x48
panic({0x7ff78dd44620?, 0x7ff78e879000?})
	runtime/panic.go:783 +0x120
github.com/microsoft/typescript-go/internal/ls/change.deleteNodeInList(0x4006ca52d0, 0x40066037e0, 0x4008fd0f08, 0x40050a4aa8)
	github.com/microsoft/typescript-go/internal/ls/change/delete.go:198 +0x38
github.com/microsoft/typescript-go/internal/ls/change.deleteDeclaration(0x4006ca52d0, 0x1?, 0x4008fd0f08, 0x40050a4aa8)
	github.com/microsoft/typescript-go/internal/ls/change/delete.go:67 +0x470
github.com/microsoft/typescript-go/internal/ls/change.(*Tracker).finishDeleteDeclarations(0x4006ca52d0)
	github.com/microsoft/typescript-go/internal/ls/change/tracker.go:233 +0xa0
github.com/microsoft/typescript-go/internal/ls/change.(*Tracker).GetChanges(0x4006ca52d0)
	github.com/microsoft/typescript-go/internal/ls/change/tracker.go:116 +0x20
github.com/microsoft/typescript-go/internal/ls/autoimport.(*Fix).Edits(0x40093e0ed0, {0x7ff78e20ac88, 0x40093e0d80}, 0x4008fd0f08, 0x40003a4308, 0x4006ca5260, 0x4000425d58, 0x400143e200)
	github.com/microsoft/typescript-go/internal/ls/autoimport/fix.go:114 +0x5ec
github.com/microsoft/typescript-go/internal/ls.getImportCodeActions({0x7ff78e20ac88, 0x40093e0d80}, 0x400734c8c0)
	github.com/microsoft/typescript-go/internal/ls/codeactions_importfixes.go:71 +0x16c
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).ProvideCodeActions(0x400734c880, {0x7ff78e20ac88, 0x40093e0d80}, 0x40073c69c0)
	github.com/microsoft/typescript-go/internal/ls/codeactions.go:85 +0x1f0
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleCodeAction(0x50054fdd0?, {0x7ff78e20ac88?, 0x40093e0d80?}, 0x40075ea210?, 0x400054fdb8?)
	github.com/microsoft/typescript-go/internal/lsp/server.go:1163 +0x2c
github.com/microsoft/typescript-go/internal/lsp.init.func1.registerLanguageServiceWithAutoImportsRequestHandler[...].29({0x7ff78e20ac88, 0x40093e0d80}, 0x400932c120)
	github.com/microsoft/typescript-go/internal/lsp/server.go:678 +0xf0
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleRequestOrNotification(0x4000180e08, {0x7ff78e20acc0?, 0x40093d25f0?}, 0x400932c120)
	github.com/microsoft/typescript-go/internal/lsp/server.go:527 +0x178
github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop.func1()
	github.com/microsoft/typescript-go/internal/lsp/server.go:414 +0x40
created by github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop in goroutine 10
	github.com/microsoft/typescript-go/internal/lsp/server.go:434 +0x7b0

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions