Skip to content

go/types, types2: nonsensical error message and position when type argument does not match constraint #45985

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

Closed
findleyr opened this issue May 6, 2021 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@findleyr
Copy link
Member

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 added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 6, 2021
@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
Contributor

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

@gopherbot
Copy link
Contributor

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 <[email protected]>
Run-TryBot: Robert Findley <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Robert Griesemer <[email protected]>
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 <[email protected]>
Reviewed-by: Robert Findley <[email protected]>
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/362634 mentions this issue: cmd/compile: fix type error reported on the wrong line

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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