Closed
Description
Starting from 7.0.0-dev.20250530.1
this issue start happening on my project.
I tracked down the offending commit (by locally building tsgo)
repro (thanks to @joshcartme ) https://github.com/joshcartme/tsgo-slice-bounds-repro.
Update: It happens for me when a file using React
types without importing React which was supported on 5.8 and previously on tsgo.
Example:
component: React.ComponentType<any>
Here is full output
> /Users/hrh/project/typescript-go/built/local/tsgo --noEmit --skipLibCheck --project tsconfig.json
panic: runtime error: slice bounds out of range [:59935] with length 1010
goroutine 1 [running]:
github.com/microsoft/typescript-go/internal/scanner.GetLineAndCharacterOfPosition({0x104f145a8, 0x140098a1348}, 0xea1f)
/Users/hrh/project/typescript-go/internal/scanner/scanner.go:2322 +0x158
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).visitDeclarationSubtree(0x140ba05fb20, 0x14003dd1600)
/Users/hrh/project/typescript-go/internal/transformers/declarations/transform.go:470 +0x808
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).visit(0x140002f1718?, 0x1048ea4cc?)
/Users/hrh/project/typescript-go/internal/transformers/declarations/transform.go:143 +0x114
github.com/microsoft/typescript-go/internal/ast.(*NodeVisitor).VisitSlice(0x140bb73f500, {0x14003deb288, 0x2, 0x2})
/Users/hrh/project/typescript-go/internal/ast/visitor.go:148 +0xa0
github.com/microsoft/typescript-go/internal/ast.(*NodeVisitor).VisitNodes(0x140bb73f500, 0x14004898128)
/Users/hrh/project/typescript-go/internal/ast/visitor.go:99 +0x40
github.com/microsoft/typescript-go/internal/ast.(*NodeVisitor).visitNodes(0x140002f1818?, 0x104b79aa8?)
/Users/hrh/project/typescript-go/internal/ast/visitor.go:236 +0x44
github.com/microsoft/typescript-go/internal/ast.(*UnionTypeNode).VisitEachChild(0x14003dd1680, 0x140bb73f500)
/Users/hrh/project/typescript-go/internal/ast/ast.go:6997 +0x30
github.com/microsoft/typescript-go/internal/ast.(*Node).VisitEachChild(...)
/Users/hrh/project/typescript-go/internal/ast/ast.go:217
github.com/microsoft/typescript-go/internal/ast.(*NodeVisitor).VisitEachChild(...)
/Users/hrh/project/typescript-go/internal/ast/visitor.go:191
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).visitDeclarationSubtree(0x140ba05fb20, 0x14003dd1680)
/Users/hrh/project/typescript-go/internal/transformers/declarations/transform.go:493 +0xce8
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).visit(0x104b33700?, 0x140ba06db88?)
/Users/hrh/project/typescript-go/internal/transformers/declarations/transform.go:143 +0x114
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).transformTypeAliasDeclaration(0x140ba05fb20, 0x14004049100)
/Users/hrh/project/typescript-go/internal/transformers/declarations/transform.go:1122 +0x78
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).transformTopLevelDeclaration(0x140ba05fb20, 0x14004049100)
/Users/hrh/project/typescript-go/internal/transformers/declarations/transform.go:1090 +0x468
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).visitDeclarationStatements(0x140ba05fb20, 0x14004049100)
/Users/hrh/project/typescript-go/internal/transformers/declarations/transform.go:940 +0x4c
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).visit(0x140002f1bc8?, 0x104b80454?)
/Users/hrh/project/typescript-go/internal/transformers/declarations/transform.go:118 +0xec
github.com/microsoft/typescript-go/internal/ast.(*NodeVisitor).VisitSlice(0x140bb73f500, {0x140023f5608, 0x106, 0x106})
/Users/hrh/project/typescript-go/internal/ast/visitor.go:148 +0xa0
github.com/microsoft/typescript-go/internal/ast.(*NodeVisitor).VisitNodes(0x140bb73f500, 0x140041e7ce8)
/Users/hrh/project/typescript-go/internal/ast/visitor.go:99 +0x40
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).transformModuleDeclaration(0x140ba05fb20, 0x14003a26090)
/Users/hrh/project/typescript-go/internal/transformers/declarations/transform.go:1179 +0xb8
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).transformTopLevelDeclaration(0x140ba05fb20, 0x14003a26090)
/Users/hrh/project/typescript-go/internal/transformers/declarations/transform.go:1096 +0x438
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).transformAndReplaceLatePaintedStatements(0x140ba05fb20, 0x140098b4500)
/Users/hrh/project/typescript-go/internal/transformers/declarations/transform.go:235 +0xf4
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).transformSourceFile(0x140ba05fb20, 0x140098a1348)
/Users/hrh/project/typescript-go/internal/transformers/declarations/transform.go:186 +0x40
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).visitSourceFile(0x140ba05fb20, 0x140098a1348)
/Users/hrh/project/typescript-go/internal/transformers/declarations/transform.go:172 +0x174
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).visit(0x140ba05fb20?, 0x140845f24e0?)
/Users/hrh/project/typescript-go/internal/transformers/declarations/transform.go:102 +0xc0
github.com/microsoft/typescript-go/internal/ast.(*NodeVisitor).VisitNode(0x1133319f8?, 0x140c9250c68?)
/Users/hrh/project/typescript-go/internal/ast/visitor.go:51 +0x30
github.com/microsoft/typescript-go/internal/ast.(*NodeVisitor).VisitSourceFile(...)
/Users/hrh/project/typescript-go/internal/ast/visitor.go:36
github.com/microsoft/typescript-go/internal/transformers.(*Transformer).TransformSourceFile(...)
/Users/hrh/project/typescript-go/internal/transformers/transformer.go:42
github.com/microsoft/typescript-go/internal/compiler.getDeclarationDiagnostics({0x104f24c90, 0x140c9250c68}, {0x104f264f8, 0x140377529a0}, 0x140098a1348)
/Users/hrh/project/typescript-go/internal/compiler/emitter.go:477 +0x134
github.com/microsoft/typescript-go/internal/compiler.(*Program).getDeclarationDiagnosticsForFile(0x1400049c540, {0x140000921a0?, 0x1403327d008?}, 0x140098a1348)
/Users/hrh/project/typescript-go/internal/compiler/program.go:576 +0x84
github.com/microsoft/typescript-go/internal/compiler.(*Program).getDiagnosticsHelper(0x1400049c540, {0x104f15568, 0x1053ea660}, 0x0?, 0x0?, 0x1?, 0x140002f2390)
/Users/hrh/project/typescript-go/internal/compiler/program.go:678 +0x1a0
github.com/microsoft/typescript-go/internal/compiler.(*Program).GetDeclarationDiagnostics(...)
/Users/hrh/project/typescript-go/internal/compiler/program.go:467
github.com/microsoft/typescript-go/internal/execute.emitFilesAndReportErrors({0x104f19750, 0x140000c4a50}, 0x1400049c540, 0x14000092d00)
/Users/hrh/project/typescript-go/internal/execute/tsc.go:277 +0x4b4
github.com/microsoft/typescript-go/internal/execute.performCompilation({0x104f19750, 0x140000c4a50}, 0x0, 0x14000192000, 0x14000092d00)
/Users/hrh/project/typescript-go/internal/execute/tsc.go:207 +0x1a4
github.com/microsoft/typescript-go/internal/execute.executeCommandLineWorker({0x104f19750, 0x140000c4a50}, 0x0, 0x14000192090)
/Users/hrh/project/typescript-go/internal/execute/tsc.go:135 +0x65c
github.com/microsoft/typescript-go/internal/execute.CommandLine({0x104f19750, 0x140000c4a50}, 0x0, {0x140000c4010, 0x4, 0x4})
/Users/hrh/project/typescript-go/internal/execute/tsc.go:35 +0x1f4
main.runMain()
/Users/hrh/project/typescript-go/cmd/tsgo/main.go:23 +0x120
main.main()
/Users/hrh/project/typescript-go/cmd/tsgo/main.go:10 +0x1c
Completed with failure in 3985ms