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

testing: t.Helper() confused by generics #52237

Open
carlmjohnson opened this issue Apr 8, 2022 · 1 comment
Open

testing: t.Helper() confused by generics #52237

carlmjohnson opened this issue Apr 8, 2022 · 1 comment
Labels
generics NeedsInvestigation release-blocker
Milestone

Comments

@carlmjohnson
Copy link
Contributor

@carlmjohnson carlmjohnson commented Apr 8, 2022

If you make a typed alias to a function, t.Helper() gets confused about where the error comes from.

What version of Go are you using (go version)?

1.18

Does this issue reproduce with the latest release?

Yes.

What did you do?

https://go.dev/play/p/GOOGiEsdm_O

func Helper[T any](t *testing.T) {
	t.Helper()
	t.Error("x")
}

var typedHelper = Helper[int]

func TestHelper(t *testing.T) {
	Helper[int](t)
	typedHelper(t)
}

What did you expect to see?

    prog.go:13: x
    prog.go:14: x

What did you see instead?

    prog.go:13: x
    prog.go:10: x  ← this is the line where typedHelper is defined

By contrast, this works correctly:

func Helper(t *testing.T) {
	t.Helper()
	t.Error("x")
}

var aliased = Helper

func TestHelper(t *testing.T) {
	Helper(t)
	aliased(t)
}
@ianlancetaylor ianlancetaylor added the NeedsInvestigation label Apr 8, 2022
@ianlancetaylor ianlancetaylor added this to the Go1.19 milestone Apr 8, 2022
carlmjohnson added a commit to carlmjohnson/be that referenced this issue Apr 11, 2022
carlmjohnson added a commit to carlmjohnson/be that referenced this issue Apr 11, 2022
carlmjohnson added a commit to carlmjohnson/be that referenced this issue Apr 11, 2022
carlmjohnson added a commit to carlmjohnson/be that referenced this issue Apr 11, 2022
@heschi heschi added the generics label May 11, 2022
@heschi
Copy link
Contributor

@heschi heschi commented May 11, 2022

cc @randall77: ping: this is a release blocker that hasn't been updated in a while.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generics NeedsInvestigation release-blocker
Projects
None yet
Development

No branches or pull requests

3 participants