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

Closed
rsc opened this issue Nov 20, 2023 · 3 comments
Closed

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

rsc opened this issue Nov 20, 2023 · 3 comments
Assignees
Labels
BadErrorMessage Issues related compiler error messages that should be better. compiler/runtime Issues related to the Go compiler and/or runtime. FixPending Issues that have a fix which has not yet been reviewed or submitted. 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
Contributor

@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

@mknyszek mknyszek modified the milestones: Go1.22, Go1.23 Nov 29, 2023
@dmitshur dmitshur added the FixPending Issues that have a fix which has not yet been reviewed or submitted. label Dec 8, 2023
@griesemer griesemer added the BadErrorMessage Issues related compiler error messages that should be better. label Dec 8, 2023
@griesemer griesemer modified the milestones: Go1.23, Go1.22 Dec 8, 2023
@griesemer
Copy link
Contributor

Changed to 1.22 again. The CL was ready before the change to 1.23. The change simply produces a better error message in case of an error. This is safe, even if late in the game.

ezz-no pushed a commit to ezz-no/go-ezzno that referenced this issue Feb 18, 2024
…e params and arguments

Fixes golang#64276

Change-Id: Ib6651669904e6ea0daf275d85d8bd008b8b21cc6
Reviewed-on: https://go-review.googlesource.com/c/go/+/544018
Reviewed-by: raghvender sundarjee <raghvenders@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BadErrorMessage Issues related compiler error messages that should be better. compiler/runtime Issues related to the Go compiler and/or runtime. FixPending Issues that have a fix which has not yet been reviewed or submitted. NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants