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

Closed
findleyr opened this issue Oct 13, 2021 · 2 comments
Closed

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

findleyr opened this issue Oct 13, 2021 · 2 comments
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. release-blocker
Milestone

Comments

@findleyr
Copy link
Contributor

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) {
        t.Error("bad")
}
/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:
https://cs.opensource.google/go/go/+/master:src/cmd/go/internal/load/test.go;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?

@findleyr findleyr added this to the Go1.18 milestone Oct 13, 2021
@findleyr findleyr added release-blocker NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. labels Oct 13, 2021
@bcmills
Copy link
Member

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.)

@gopherbot
Copy link

Change https://golang.org/cl/355889 mentions this issue: cmd/go: produce a better error for generic test functions

@golang golang locked and limited conversation to collaborators Oct 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. release-blocker
Projects
None yet
Development

No branches or pull requests

3 participants