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: wrong signature error when using a type alias for *testing.T #62454

Open
ghost opened this issue Sep 5, 2023 · 3 comments
Open

cmd/go: wrong signature error when using a type alias for *testing.T #62454

ghost opened this issue Sep 5, 2023 · 3 comments
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@ghost
Copy link

ghost commented Sep 5, 2023

Seems you can't alias testing.T, it confuses go test. Confuses Go Playground too.

go version go1.18.1 linux/amd64

What did you do?

https://go.dev/play/p/21W7rITsLUb

What did you expect to see?

Test results

What did you see instead?

wrong signature for TestLastIndex, must be: func TestLastIndex(t *testing.T)

@cherrymui cherrymui changed the title testing : Using type alias in test function generates compiler error testing : using type alias in test function generates compiler error Sep 5, 2023
@cherrymui cherrymui changed the title testing : using type alias in test function generates compiler error testing: using type alias in test function generates compiler error Sep 5, 2023
@cherrymui
Copy link
Member

Do you have a specific reason for aliasing testing.T? Thanks.

cc @bcmills

@cherrymui cherrymui added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 5, 2023
@cherrymui cherrymui added this to the Unplanned milestone Sep 5, 2023
@ghost
Copy link
Author

ghost commented Sep 6, 2023

Do you have a specific reason for aliasing testing.T? Thanks.

Not really, no. I alias struct pointer types so it becomes impossible to forget the * and makes refactoring easier later. But apparently *testing.T is special.

@bcmills bcmills changed the title testing: using type alias in test function generates compiler error cmd/go: wrong signature error when using a type alias for *testing.T Sep 6, 2023
@bcmills bcmills added the GoCommand cmd/go label Sep 6, 2023
@wangxuw
Copy link

wangxuw commented Sep 10, 2023

hi, I reproduced this error using the provided test code snippet. This error is returned from https://github.com/golang/go/blob/master/src/cmd/go/internal/load/test.go#L770.
And it comes from a type assertion, https://github.com/golang/go/blob/master/src/cmd/go/internal/load/test.go#L575 where go command checks whether the first param holds *ast.StarExpr. When aliasing testing.T, the underlying type for fn.Type.Params.List[0].Type would be *ast.Ident.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants