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

cmd/go: check that test funcs have no type parameters #48953

findleyr opened this issue Oct 13, 2021 · 2 comments

cmd/go: check that test funcs have no type parameters #48953

findleyr opened this issue Oct 13, 2021 · 2 comments


Copy link

@findleyr findleyr commented Oct 13, 2021

Currently, when writing a test function with type parameters, cmd/go produces an error like this:

package p

import "testing"

func TestP[P any](t *testing.T) {
/tmp/go-build4080445357/b001/_testmain.go:21:12: cannot use generic function _test.TestP without instantiation

Presumably because the generated code tries to call the generic test func without type arguments.

We should provide a more helpful error message, to the effect of "test functions cannot have type parameters". It looks like it would suffice to add this check here:;l=680;drc=5abfd2379b2e7319d3f08f496c12acdb50e1065a
(note that we probably want to continue matching these funcs in isTestFunc, specifically so that we can provide a useful error)

@bcmills @matloob does this make sense? Did you have a different behavior in mind? Shall I send a CL?

Copy link

@bcmills bcmills commented Oct 13, 2021

I agree that load.checkTestFunc is probably the right place for this fix.

(It's a bit unfortunate that isTestFunc is analyzing syntax rather than, say, extracting the actual function signatures — such as from the compiler's export data — but that seems like a separate cleanup.)

Copy link

@gopherbot gopherbot commented Oct 14, 2021

Change mentions this issue: cmd/go: produce a better error for generic test functions

@gopherbot gopherbot closed this in 4cbc0a5 Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants