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

Closed
earthboundkid opened this issue Apr 8, 2022 · 2 comments
Closed

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

earthboundkid opened this issue Apr 8, 2022 · 2 comments
Labels
FrozenDueToAge generics Issue is related to generics NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Milestone

Comments

@earthboundkid
Copy link
Contributor

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 Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 8, 2022
@ianlancetaylor ianlancetaylor added this to the Go1.19 milestone Apr 8, 2022
earthboundkid added a commit to earthboundkid/be that referenced this issue Apr 11, 2022
earthboundkid added a commit to earthboundkid/be that referenced this issue Apr 11, 2022
earthboundkid added a commit to earthboundkid/be that referenced this issue Apr 11, 2022
earthboundkid added a commit to earthboundkid/be that referenced this issue Apr 11, 2022
@heschi heschi added the generics Issue is related to generics label May 11, 2022
@heschi
Copy link
Contributor

heschi commented May 11, 2022

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

@gopherbot
Copy link

Change https://go.dev/cl/408876 mentions this issue: cmd/compile: mark closures made for generic function expressions as wrappers

@golang golang locked and limited conversation to collaborators May 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge generics Issue is related to generics NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Projects
None yet
Development

No branches or pull requests

4 participants