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

go/types, types2: better error message for cases of reverse type inference #60747

Closed
griesemer opened this issue Jun 12, 2023 · 4 comments
Closed
Assignees
Labels
BadErrorMessage Issues related compiler error messages that should be better. NeedsFix The path to resolution is known, but the work has not been done. TypeInference Issue is related to generic type inference
Milestone

Comments

@griesemer
Copy link
Contributor

This is a reminder issue to follow up on feedback in https://go.dev/cl/501938 (#60688).

v9 func(string) []int = f5 // ERROR "type func(string) []int of variable in assignment does not match inferred type func(string) []string for func(P) []P"

Feedback (@findleyr):

I think a better error would be "type func(string) []int of variable v9 does not match inferred type func(string) []string for f5"

@griesemer griesemer added the NeedsFix The path to resolution is known, but the work has not been done. label Jun 12, 2023
@griesemer griesemer added this to the Go1.22 milestone Jun 12, 2023
@griesemer griesemer self-assigned this Jun 12, 2023
@griesemer griesemer added the TypeInference Issue is related to generic type inference label Aug 16, 2023
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/546456 mentions this issue: types2: better error message for cases of reverse type inference

@griesemer griesemer added the BadErrorMessage Issues related compiler error messages that should be better. label Dec 7, 2023
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/548995 mentions this issue: go/types, types2: better error message for cases of reverse type inference

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/549055 mentions this issue: go/types, types2: flip message contents for for reverse type inference errors

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/549055 mentions this issue: go/types, types2: flip message contents for reverse type inference errors

gopherbot pushed a commit that referenced this issue Dec 12, 2023
…rence

Introduce a new type "target" to pass around target types together
with a suitable description (typically a variable name) for a better
error message.

As a side effect, using a specific type (target), rather than just Type
avoids accidental confusion with other types.

Use the target type description for a better error message in some
cases.

The error message can be further improved by flipping the order of
the sentence (for another CL to keep this one small and simple).

Also, and unrelated to this fix, remove the first argument to errorf
in infer.go: the argument is always "type" (there's only one call).

For #60747.

Change-Id: I2118d0fe9e2b4aac959371941064e0e9ca7b3b6e
Reviewed-on: https://go-review.googlesource.com/c/go/+/548995
Auto-Submit: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
ezz-no pushed a commit to ezz-no/go-ezzno that referenced this issue Feb 18, 2024
…rence

Introduce a new type "target" to pass around target types together
with a suitable description (typically a variable name) for a better
error message.

As a side effect, using a specific type (target), rather than just Type
avoids accidental confusion with other types.

Use the target type description for a better error message in some
cases.

The error message can be further improved by flipping the order of
the sentence (for another CL to keep this one small and simple).

Also, and unrelated to this fix, remove the first argument to errorf
in infer.go: the argument is always "type" (there's only one call).

For golang#60747.

Change-Id: I2118d0fe9e2b4aac959371941064e0e9ca7b3b6e
Reviewed-on: https://go-review.googlesource.com/c/go/+/548995
Auto-Submit: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
ezz-no pushed a commit to ezz-no/go-ezzno that referenced this issue Feb 18, 2024
…rors

Add a new flag 'reverse' to control the formatting of type inference
error messages.

This change only impacts error messages.

Fixes golang#60747.

Change-Id: I81e13075e3157252ccc09f358bd29bd676c34499
Reviewed-on: https://go-review.googlesource.com/c/go/+/549055
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: 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. NeedsFix The path to resolution is known, but the work has not been done. TypeInference Issue is related to generic type inference
Projects
None yet
Development

No branches or pull requests

2 participants