Skip to content

Panic formatting chained method call #1928

@mjbvz

Description

@mjbvz

Stack trace

panic handling request textDocument/formatting strings: negative Repeat count goroutine 473 [running]:
runtime/debug.Stack()
	runtime/debug/stack.go:26 +0x64
github.com/microsoft/typescript-go/internal/lsp.(*Server).recover(0x14000000f00, 0x14001b29110)
	github.com/microsoft/typescript-go/internal/lsp/server.go:539 +0x44
panic({0x10323fae0?, 0x103455c10?})
	runtime/panic.go:783 +0x120
strings.Repeat({0x1031b4db8?, 0x140030cf970?}, 0x14001b64a98?)
	strings/strings.go:628 +0x574
github.com/microsoft/typescript-go/internal/format.getIndentationString(0xffffffffffffffff, 0x102c74d04?)
	github.com/microsoft/typescript-go/internal/format/span.go:976 +0x54
github.com/microsoft/typescript-go/internal/format.(*formatSpanWorker).insertIndentation(0x140006beff0, 0xd, 0xffffffffffffffff, 0x0)
	github.com/microsoft/typescript-go/internal/format/span.go:859 +0x3c
github.com/microsoft/typescript-go/internal/format.(*formatSpanWorker).consumeTokenAndAdvanceScanner.func1({{0x2a34570?, 0x140?}, 0x2?})
	github.com/microsoft/typescript-go/internal/format/span.go:1059 +0x2c
github.com/microsoft/typescript-go/internal/format.(*formatSpanWorker).indentTriviaItems(0x140006beff0, {0x1400239d2f0?, 0x1d?, 0x1400017f398?}, 0xffffffffffffffff, 0x98?, 0x14001b64ba0)
	github.com/microsoft/typescript-go/internal/format/span.go:900 +0x94
github.com/microsoft/typescript-go/internal/format.(*formatSpanWorker).consumeTokenAndAdvanceScanner(0x140006beff0, {{0x1400239d2f0, 0x4, 0x4}, {{0x1f, 0x20}, 0x18}, {0x0, 0x0, 0x0}}, ...)
	github.com/microsoft/typescript-go/internal/format/span.go:1058 +0x2d4
github.com/microsoft/typescript-go/internal/format.(*formatSpanWorker).processChildNode(0x140006beff0, 0x1400017f398, 0x14002361af0?, 0x1400032a9c0?, 0x14003394dd8?, 0x140006127e0, 0xffffffffffffffff, 0x1400017f398, 0x14002a34570, 0x0, ...)
	github.com/microsoft/typescript-go/internal/format/span.go:389 +0x2d4
github.com/microsoft/typescript-go/internal/format.(*formatSpanWorker).execute.func1(0x140006127e0)
	github.com/microsoft/typescript-go/internal/format/span.go:230 +0x54
github.com/microsoft/typescript-go/internal/ast.(*NodeVisitor).VisitNode(0x14003394f38?, 0x2f51b60?)
	github.com/microsoft/typescript-go/internal/ast/visitor.go:51 +0x30
github.com/microsoft/typescript-go/internal/ast.(*NodeVisitor).visitNode(0x103b5dd58?, 0x30?)
	github.com/microsoft/typescript-go/internal/ast/visitor.go:198 +0x44
github.com/microsoft/typescript-go/internal/ast.(*PropertyAccessExpression).VisitEachChild(0x1400017f398, 0x1400032aae0)
	github.com/microsoft/typescript-go/internal/ast/ast.go:6716 +0x58
github.com/microsoft/typescript-go/internal/ast.(*Node).VisitEachChild(...)
	github.com/microsoft/typescript-go/internal/ast/ast.go:245
github.com/microsoft/typescript-go/internal/format.(*formatSpanWorker).executeProcessNodeVisitor(0x140006beff0, 0x102c74d04?, 0x14003394e98?, 0x102f3d370?, 0x0?)
	github.com/microsoft/typescript-go/internal/format/span.go:523 +0x6c
github.com/microsoft/typescript-go/internal/format.(*formatSpanWorker).processNode(0x140006beff0, 0x1400017f398, 0x140006d0f08, 0x0, 0x0, 0xffffffffffffffff, 0x4)
	github.com/microsoft/typescript-go/internal/format/span.go:620 +0x120
github.com/microsoft/typescript-go/internal/format.(*formatSpanWorker).processChildNode(0x140006beff0, 0x1400017f448, 0x14000968a20?, 0x102ae925c?, 0x140033950d8?, 0x1400017f398, 0xffffffffffffffff, 0x1400017f448, 0x14002a34540, 0x0, ...)
	github.com/microsoft/typescript-go/internal/format/span.go:413 +0x5a8
github.com/microsoft/typescript-go/internal/format.(*formatSpanWorker).execute.func1(0x1400017f398)
	github.com/microsoft/typescript-go/internal/format/span.go:230 +0x54
github.com/microsoft/typescript-go/internal/ast.(*NodeVisitor).VisitNode(0x103b5dd58?, 0x2030cf8b0?)
	github.com/microsoft/typescript-go/internal/ast/visitor.go:51 +0x30
github.com/microsoft/typescript-go/internal/ast.(*NodeVisitor).visitNode(0x500000000?, 0x12ab97e80?)
	github.com/microsoft/typescript-go/internal/ast/visitor.go:198 +0x44
github.com/microsoft/typescript-go/internal/ast.(*CallExpression).VisitEachChild(0x1400017f448, 0x1400032aae0)
	github.com/microsoft/typescript-go/internal/ast/ast.go:6827 +0x30
github.com/microsoft/typescript-go/internal/ast.(*Node).VisitEachChild(...)
	github.com/microsoft/typescript-go/internal/ast/ast.go:245
github.com/microsoft/typescript-go/internal/format.(*formatSpanWorker).executeProcessNodeVisitor(0x140006beff0, 0x102c74d04?, 0x14003395228?, 0x102f3d370?, 0x0?)
	github.com/microsoft/typescript-go/internal/format/span.go:523 +0x6c
github.com/microsoft/typescript-go/internal/format.(*formatSpanWorker).processNode(0x140006beff0, 0x1400017f448, 0x140006d0f08, 0x0, 0x0, 0xffffffffffffffff, 0x4)
	github.com/microsoft/typescript-go/internal/format/span.go:620 +0x120
github.com/microsoft/typescript-go/internal/format.(*formatSpanWorker).processChildNode(0x140006beff0, 0x14002541a80, 0x14002a34510?, 0x0?, 0x0?, 0x1400017f448, 0xffffffffffffffff, 0x14002541a80, 0x14002a34510, 0x0, ...)
	github.com/microsoft/typescript-go/internal/format/span.go:413 +0x5a8
github.com/microsoft/typescript-go/internal/format.(*formatSpanWorker).execute.func1(0x1400017f448)
	github.com/microsoft/typescript-go/internal/format/span.go:230 +0x54
github.com/microsoft/typescript-go/internal/ast.(*NodeVisitor).VisitNode(0x103b5dd58?, 0x30?)
	github.com/microsoft/typescript-go/internal/ast/visitor.go:51 +0x30
github.com/microsoft/typescript-go/internal/ast.(*NodeVisitor).visitNode(0x14000a4f4f8?, 0x102a8c8cc?)
	github.com/microsoft/typescript-go/internal/ast/visitor.go:198 +0x44
github.com/microsoft/typescript-go/internal/ast.(*ExpressionStatement).VisitEachChild(0x14002541a80, 0x1400032aae0)
	github.com/microsoft/typescript-go/internal/ast/ast.go:3619 +0x30
github.com/microsoft/typescript-go/internal/ast.(*Node).VisitEachChild(...)
	github.com/microsoft/typescript-go/internal/ast/ast.go:245
github.com/microsoft/typescript-go/internal/format.(*formatSpanWorker).executeProcessNodeVisitor(0x140006beff0, 0x102c74d04?, 0x14000a4f588?, 0x102f3d370?, 0x0?)
	github.com/microsoft/typescript-go/internal/format/span.go:523 +0x6c
github.com/microsoft/typescript-go/internal/format.(*formatSpanWorker).processNode(0x140006beff0, 0x14002541a80, 0x140006d0f08, 0x0, 0x0, 0xffffffffffffffff, 0x4)
	github.com/microsoft/typescript-go/internal/format/span.go:620 +0x120
github.com/microsoft/typescript-go/internal/format.(*formatSpanWorker).processChildNode(0x140006beff0, 0x140006d0f08, 0x1400019eb40?, 0x1400017f340?, 0x14000a4f7b8?, 0x14002541a80, 0xffffffffffffffff, 0x140006d0f08, 0x14002a344e0, 0x0, ...)
	github.com/microsoft/typescript-go/internal/format/span.go:413 +0x5a8
github.com/microsoft/typescript-go/internal/format.(*formatSpanWorker).processChildNodes(0x140006beff0, 0x140006d0f08, 0x14002a344e0, 0x0, 0x0, 0x14002541b00, 0x140006d0f08, 0x0, 0x14002a344e0)
	github.com/microsoft/typescript-go/internal/format/span.go:487 +0x1d8
github.com/microsoft/typescript-go/internal/format.(*formatSpanWorker).execute.func2(0x14002541b00, 0x102bcfb64?)
	github.com/microsoft/typescript-go/internal/format/span.go:237 +0x44
github.com/microsoft/typescript-go/internal/ast.(*NodeVisitor).visitNodes(0x500000000?, 0x12ab97e80?)
	github.com/microsoft/typescript-go/internal/ast/visitor.go:234 +0x34
github.com/microsoft/typescript-go/internal/ast.(*NodeVisitor).visitTopLevelStatements(0x14000200008?, 0x14002a344e0?)
	github.com/microsoft/typescript-go/internal/ast/visitor.go:257 +0x44
github.com/microsoft/typescript-go/internal/ast.(*SourceFile).VisitEachChild(0x140006d0f08, 0x1400032aae0)
	github.com/microsoft/typescript-go/internal/ast/ast.go:10820 +0x30
github.com/microsoft/typescript-go/internal/ast.(*Node).VisitEachChild(...)
	github.com/microsoft/typescript-go/internal/ast/ast.go:245
github.com/microsoft/typescript-go/internal/format.(*formatSpanWorker).executeProcessNodeVisitor(0x140006beff0, 0x102c74d04?, 0x14000a4f9e8?, 0x102a8bdf8?, 0x14000a4fa38?)
	github.com/microsoft/typescript-go/internal/format/span.go:523 +0x6c
github.com/microsoft/typescript-go/internal/format.(*formatSpanWorker).processNode(0x140006beff0, 0x140006d0f08, 0x140006d0f08, 0x0, 0x0, 0x0, 0x0)
	github.com/microsoft/typescript-go/internal/format/span.go:620 +0x120
github.com/microsoft/typescript-go/internal/format.(*formatSpanWorker).execute(0x140006beff0, 0x102a8c8cc?)
	github.com/microsoft/typescript-go/internal/format/span.go:251 +0x3d4
github.com/microsoft/typescript-go/internal/format.newFormattingScanner({0x140031aff80, 0x27}, 0x0, 0x0, 0x27, 0x140006beff0)
	github.com/microsoft/typescript-go/internal/format/scanner.go:57 +0x1fc
github.com/microsoft/typescript-go/internal/format.FormatSpan({0x10345e340, 0x14002a344b0}, {0x0, 0x27}, 0x140006d0f08, 0x0)
	github.com/microsoft/typescript-go/internal/format/api.go:60 +0x1c8
github.com/microsoft/typescript-go/internal/format.FormatDocument({0x10345e340?, 0x14002a344b0?}, 0x18?)
	github.com/microsoft/typescript-go/internal/format/api.go:108 +0x34
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).getFormattingEditsForDocument(0x14002966c60?, {0x10345e378?, 0x14002b40be0?}, 0x140006d0f08, 0x0?)
	github.com/microsoft/typescript-go/internal/ls/format.go:104 +0x44
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).ProvideFormatDocument(0x14002a34420, {0x10345e378, 0x14002b40be0}, {0x140020356e0?, 0x1400030e000?}, 0x14002966c60)
	github.com/microsoft/typescript-go/internal/ls/format.go:46 +0xb4
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleDocumentFormat(0x1400030e000?, {0x10345e378?, 0x14002b40be0?}, 0x140020356e0?, 0x28?)
	github.com/microsoft/typescript-go/internal/lsp/server.go:817 +0x38
github.com/microsoft/typescript-go/internal/lsp.init.func1.registerLanguageServiceDocumentRequestHandler[...].19({0x10345e378, 0x14002b40be0}, 0x14001b29110)
	github.com/microsoft/typescript-go/internal/lsp/server.go:525 +0xe0
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleRequestOrNotification(0x14000000f00, {0x10345e378, 0x14002b40be0}, 0x14001b29110)
	github.com/microsoft/typescript-go/internal/lsp/server.go:422 +0xf4
github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop.func1()
	github.com/microsoft/typescript-go/internal/lsp/server.go:327 +0x34
created by github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop in goroutine 18
	github.com/microsoft/typescript-go/internal/lsp/server.go:347 +0x6f8

Steps to reproduce

Format the following file:

foo
	.bar()
	// A second call
	.baz();

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions