Skip to content

go/printer: Fprint crashes with unexpected parenthesized expression panic #69206

@mateusz834

Description

@mateusz834

Reproducer:

func TestPrinterPanic(t *testing.T) {
	const src = `package A
type A[C((D)),] struct{}
`

	fs := token.NewFileSet()
	f, err := parser.ParseFile(fs, "test.go", src, parser.ParseComments|parser.SkipObjectResolution)
	if err != nil {
		t.Fatal(err)
	}
	Fprint(io.Discard, fs, f) // panic: unexpected parenthesized expression.
}
panic: unexpected parenthesized expression [recovered]
        panic: unexpected parenthesized expression

goroutine 6 [running]:
testing.tRunner.func1.2({0x586300, 0x5fbc80})
        testing/testing.go:1706 +0x230
testing.tRunner.func1()
        testing/testing.go:1709 +0x35e
panic({0x586300?, 0x5fbc80?})
        runtime/panic.go:785 +0x132
go/printer.combinesWithName({0x5fe0b8?, 0xc0000700e0?})
        go/printer/nodes.go:416 +0x5c
go/printer.(*printer).parameters(0xc0000a21a0, 0xc0000845a0, 0x2)
        go/printer/nodes.go:383 +0xa3d
go/printer.(*printer).spec(0xc0000a21a0, {0x5fe358?, 0xc000090a40}, 0x1, 0x1?)
        go/printer/nodes.go:1719 +0x419
go/printer.(*printer).genDecl(0xc0000a21a0, 0xc000090b00)
        go/printer/nodes.go:1777 +0x407
go/printer.(*printer).decl(0xc0000a21a0?, {0x5fdfc8?, 0xc000090b00?})
        go/printer/nodes.go:1945 +0x51
go/printer.(*printer).declList(0xc0000a21a0, {0xc000020460?, 0xc000070060?, 0x0?})
        go/printer/nodes.go:1990 +0x39
go/printer.(*printer).file(0xc0000a21a0, 0xc000080280)
        go/printer/nodes.go:1999 +0x16f
go/printer.(*printer).printNode(0xc0000a21a0, {0x592020?, 0xc000080280?})
        go/printer/printer.go:1172 +0x16a
go/printer.(*Config).fprint(0xc0000c9f20, {0x5fcea0, 0x72a020}, 0x586300?, {0x592020, 0xc000080280}, 0x4dabc0?)
        go/printer/printer.go:1364 +0xab
go/printer.(*Config).Fprint(...)
        go/printer/printer.go:1424
go/printer.Fprint(...)
        go/printer/printer.go:1432

Metadata

Metadata

Assignees

Labels

FixPendingIssues that have a fix which has not yet been reviewed or submitted.NeedsFixThe path to resolution is known, but the work has not been done.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions