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: nonsensical error message and position when type argument does not match constraint #45985

Open
findleyr opened this issue May 6, 2021 · 2 comments
Assignees
Milestone

Comments

@findleyr
Copy link
Contributor

@findleyr findleyr commented May 6, 2021

When a function is instantiated with type arguments that don't satisfy its type parameter constraints, the error message go/types produces references the type parameter, rather than the type argument, and is also located on the parameter.

Example (this error check test currently passes in go/types):

package p

func app[S  /* ERROR "type S = S does not match" */ interface{ type []T }, T any](s S, e T) S {
        return append(s, e)
}
                                                                                                                                                    
func _() {
        _ = app[int]
}

In this case, the actual error is that app is instantiated with int rather than []int.

Confirmed that this also affects types2.

CC @griesemer

@findleyr findleyr self-assigned this May 6, 2021
@griesemer griesemer added this to the Go1.18 milestone May 6, 2021
@griesemer griesemer self-assigned this May 6, 2021
@gopherbot
Copy link

@gopherbot gopherbot commented May 6, 2021

Change https://golang.org/cl/317471 mentions this issue: go/types: add a test case for issue 45985

@gopherbot
Copy link

@gopherbot gopherbot commented May 6, 2021

Change https://golang.org/cl/317732 mentions this issue: cmd/compile/internal/types2: add test case for issue 45985

gopherbot pushed a commit that referenced this issue May 7, 2021
The fix for #45985 is a little subtle. Start by committing the (bad)
test case.

For #45985

Change-Id: Ia6625818e9b1c5e869b2c2f724f817c13c9944d1
Reviewed-on: https://go-review.googlesource.com/c/go/+/317471
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
gopherbot pushed a commit that referenced this issue May 7, 2021
This is a port of https://golang.org/cl/317471.

Updates #45985.

Change-Id: I539d0fa6f9a77eb2fc169a21c5db9921f8eceb03
Reviewed-on: https://go-review.googlesource.com/c/go/+/317732
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants