Skip to content

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

@earthboundkid

Description

@earthboundkid

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.genericsIssue is related to genericsrelease-blocker

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions