Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/types, types2: internal/types/errors panics when types.debug=true #61938

Closed
findleyr opened this issue Aug 10, 2023 · 2 comments
Closed

go/types, types2: internal/types/errors panics when types.debug=true #61938

findleyr opened this issue Aug 10, 2023 · 2 comments
Assignees
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@findleyr
Copy link
Contributor

go/types.debug enables additional checks during development.

However, I noticed that internal/types/errors.TestErrorCodeExamples/CannotInferTypeArgs actually hits one such assertion:

> go test -short
--- FAIL: TestErrorCodeExamples (0.36s)
    --- FAIL: TestErrorCodeExamples/CannotInferTypeArgs (0.00s)
panic: (types.bailout) 0x88e3a0
        panic: /home/rfindley/src/go/src/go/types/infer.go:34: assertion failed [recovered]
        panic: /home/rfindley/src/go/src/go/types/infer.go:34: assertion failed [recovered]
        panic: /home/rfindley/src/go/src/go/types/infer.go:34: assertion failed [recovered]
        panic: /home/rfindley/src/go/src/go/types/infer.go:34: assertion failed

goroutine 184 [running]:
testing.tRunner.func1.2({0x649e40, 0xc000370880})
        /home/rfindley/src/go/src/testing/testing.go:1545 +0x24a
testing.tRunner.func1()
        /home/rfindley/src/go/src/testing/testing.go:1548 +0x397
panic({0x649e40?, 0xc000370880?})
        /home/rfindley/src/go/src/runtime/panic.go:612 +0x132
go/types.(*Checker).handleBailout(0xc000354b40, 0xc000437cb0)
        /home/rfindley/src/go/src/go/types/check.go:339 +0x88
panic({0x649e40?, 0xc000370880?})
        /home/rfindley/src/go/src/runtime/panic.go:612 +0x132
go/types.(*Checker).stmt.func1(0xc000359b00)
        /home/rfindley/src/go/src/go/types/stmt.go:369 +0x52
panic({0x649e40?, 0xc000370880?})
        /home/rfindley/src/go/src/runtime/panic.go:612 +0x132
go/types.assert(0x20?)
        /home/rfindley/src/go/src/go/types/errors.go:28 +0x54
go/types.(*Checker).infer.func1()
        /home/rfindley/src/go/src/go/types/infer.go:34 +0x37
panic({0x658b60?, 0x88e3a0?})
        /home/rfindley/src/go/src/runtime/panic.go:612 +0x132
go/types.(*Checker).report(0xc000354b40, 0xc000435150)
        /home/rfindley/src/go/src/go/types/errors.go:287 +0x4df
go/types.(*Checker).errorf(...)
        /home/rfindley/src/go/src/go/types/errors.go:310
go/types.(*Checker).infer(0xc000354b40, {0x6f9000, 0xc0003536c0}, {0xc0000a2408?, 0x1, 0x1}, {0xc0003707f0, 0x1, 0x1}, 0x0, ...)
        /home/rfindley/src/go/src/go/types/infer.go:414 +0x1ea5
go/types.(*Checker).arguments(0xc000354b40, 0xc0003536c0, 0xc000353740, {0x0, 0x0, 0x0}, {0x0, 0x0, 0x0}, {0x0, ...}, ...)
        /home/rfindley/src/go/src/go/types/call.go:606 +0x119e
go/types.(*Checker).callExpr(0xc000354b40, 0xc000353880, 0xc0003536c0)
        /home/rfindley/src/go/src/go/types/call.go:302 +0x858
go/types.(*Checker).exprInternal(0xc000354b40, {0x0, 0x0}, 0xc000353880, {0x6fa4c0, 0xc0003536c0?}, {0x0?, 0x0?})
        /home/rfindley/src/go/src/go/types/expr.go:1359 +0x1889
go/types.(*Checker).rawExpr(0xc000354b40, {0x0, 0x0}, 0xc000353880, {0x6fa4c0?, 0xc0003536c0?}, {0x0?, 0x0?}, 0x0)
@findleyr findleyr added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 10, 2023
@findleyr findleyr added this to the Go1.22 milestone Aug 14, 2023
@griesemer
Copy link
Contributor

griesemer commented Aug 15, 2023

Reproducer (for inclusion in issues_test.go):

func TestIssue61938(t *testing.T) {
	const src = `
package p

func f[T any]() {}

func _() {
	f()
}
`
	var conf Config            // important: no error handler provided
	typecheck(src, &conf, nil) // must not panic
}

will panic if debug is set.

When no error handler is provided, reporting an error leads to an internal exit panic (type checking stops after first error). In this specific case, a result value is not updated which then leads to an assertion failure. Harmless because the result never gets looked at, but should probably fix.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/519775 mentions this issue: go/types, types2: don't verify infer result if no Config.Error is given

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants