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/compile: generic error does not identify relevant type #64276

Open
rsc opened this issue Nov 20, 2023 · 2 comments
Open

cmd/compile: generic error does not identify relevant type #64276

rsc opened this issue Nov 20, 2023 · 2 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Nov 20, 2023

% cat /tmp/x.go
package p

type T[X, Y any] struct {
	x X
	y Y
}

var _ T[int]

func t(x, y int) int

var _ = t(1)
% go build /tmp/x.go
# command-line-arguments
/tmp/x.go:8:7: got 1 arguments but 2 type parameters
/tmp/x.go:12:11: not enough arguments in call to t
	have (number)
	want (int, int)
% 

Note the difference in errors.

The ordinary parameter error says "not enough arguments in call to t" and then gives the argument types.

The generic error says "got 1 arguments but 2 type parameters" which does not identify the relevant type (T in this case) and is also easily misread to mean "got 1 arguments and got 2 type parameters but these numbers don't match". It would be better for this error to be worded more like the non-generic error. Perhaps:

/tmp/x.go:8:7: not enough type arguments for type T: have 1, want 2

or even

/tmp/x.go:8:7: not enough type arguments for type T
	have (int)
	want (any, any)

/cc @griesemer

@rsc rsc added the NeedsFix The path to resolution is known, but the work has not been done. label Nov 20, 2023
@rsc rsc added this to the Go1.22 milestone Nov 20, 2023
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Nov 20, 2023
@raghvenders
Copy link

@gopherbot - Assign this me.

@gopherbot
Copy link

Change https://go.dev/cl/544018 mentions this issue: cmd/compile: Fix generics error message for mismatch of number of type params and arguments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Projects
Status: No status
Development

No branches or pull requests

3 participants