Skip to content

tsgo panics when a type-only export is the body of an if statement #3904

@mariusschulz

Description

@mariusschulz

Stack trace

panic: runtime error: invalid memory address or nil pointer dereference [recovered, repanicked]
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x100be15e0]

goroutine 112 [running]:
sync.(*WaitGroup).Go.func1.1()
        sync/waitgroup.go:251 +0x48
panic({0x101b7d8e0?, 0x101f7df80?})
        runtime/panic.go:860 +0x12c
github.com/microsoft/typescript-go/internal/ast.IsBlock(...)
        github.com/microsoft/typescript-go/internal/ast/ast_generated.go:1814
github.com/microsoft/typescript-go/internal/printer.(*Printer).emitEmbeddedStatement(0x694529916a80, 0x694527ac0015?, 0x0)
        github.com/microsoft/typescript-go/internal/printer/printer.go:4095 +0x20
github.com/microsoft/typescript-go/internal/printer.(*Printer).emitIfStatement(0x694529916a80, 0x69452c792420)
        github.com/microsoft/typescript-go/internal/printer/printer.go:3435 +0xe0
github.com/microsoft/typescript-go/internal/printer.(*Printer).emitStatement(0xffffffffffffffff?, 0x69452c7a1a68?)
        github.com/microsoft/typescript-go/internal/printer/printer.go:4124 +0xc4
github.com/microsoft/typescript-go/internal/printer.(*Printer).emitListItems(0x694529916a80, 0x101dd3660, 0x69452c77e708, {0x69452c78d258, 0x1, 0x69452c77e708?}, 0x1, 0x0, {0x1?, 0x29916a80?})
        github.com/microsoft/typescript-go/internal/printer/printer.go:4928 +0x4d4
github.com/microsoft/typescript-go/internal/printer.(*Printer).emitListRange(0x694529916a80, 0x101dd3660, 0x69452c77e708, 0x69452c7908e0, 0x1, 0x694529554480?, 0x69452c7a1b68?)
        github.com/microsoft/typescript-go/internal/printer/printer.go:4727 +0x310
github.com/microsoft/typescript-go/internal/printer.(*Printer).emitSourceFile(0x694529916a80, 0x69452c77e708)
        github.com/microsoft/typescript-go/internal/printer/printer.go:4632 +0x21c
github.com/microsoft/typescript-go/internal/printer.(*Printer).Write(0x694529916a80, 0x69452c77e708, 0x69452c77e708, {0x101dfa0b0, 0x69452c7171f0}, 0x101ddef98?)
        github.com/microsoft/typescript-go/internal/printer/printer.go:5190 +0xc40
github.com/microsoft/typescript-go/internal/compiler.(*emitter).printSourceFile(0x69452c79a380, {0x694527895b60, 0x2b}, {0x0, 0x0}, 0x69452c77e708, 0x694529916a80, 0x0)
        github.com/microsoft/typescript-go/internal/compiler/emitter.go:278 +0x194
github.com/microsoft/typescript-go/internal/compiler.(*emitter).emitJSFile(0x69452c79a380, 0x694527ad0008, {0x694527895b60, 0x2b}, {0x0, 0x0})
        github.com/microsoft/typescript-go/internal/compiler/emitter.go:210 +0x2e8
github.com/microsoft/typescript-go/internal/compiler.(*emitter).emit(0x69452c79a380)
        github.com/microsoft/typescript-go/internal/compiler/emitter.go:49 +0xec
github.com/microsoft/typescript-go/internal/compiler.(*Program).Emit.func2()
        github.com/microsoft/typescript-go/internal/compiler/program.go:1649 +0x194
github.com/microsoft/typescript-go/internal/core.(*parallelWorkGroup).Queue.func1()
        github.com/microsoft/typescript-go/internal/core/workgroup.go:40 +0x24
sync.(*WaitGroup).Go.func1()
        sync/waitgroup.go:258 +0x48
created by sync.(*WaitGroup).Go in goroutine 1
        sync/waitgroup.go:238 +0x70

Steps to reproduce

if (true) export type {};

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions