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: recursive call of generic function with concrete type argument fails #48638

Closed
griesemer opened this issue Sep 27, 2021 · 3 comments

Comments

@griesemer
Copy link
Contributor

griesemer commented Sep 27, 2021

package p
func g[P any](x P) {
        g[int](x)
}

does not type-check:

cannot use x (variable of type parameter P constrained by interface{}) as int value in argument to g[int]

[edited]: This looks like a correct error message after all: If g is called as g[string]("foo"), the type of x would be string and the local call g[int](x) would be incorrect.

@griesemer griesemer added NeedsFix The path to resolution is known, but the work has not been done. release-blocker labels Sep 27, 2021
@griesemer griesemer added this to the Go1.18 milestone Sep 27, 2021
@griesemer griesemer self-assigned this Sep 27, 2021
@gopherbot
Copy link

Change https://golang.org/cl/352311 mentions this issue: cmd/compile/internal/types2: use correct argument types for recursive generic functions

@griesemer griesemer added Thinking and removed NeedsFix The path to resolution is known, but the work has not been done. release-blocker labels Sep 27, 2021
@ianlancetaylor
Copy link
Contributor

package p
func g[P any](x P) {
        g[int](x)
}

Is this code permitted at all? It is a recursive reference from g to itself with a different set of type arguments.

@griesemer
Copy link
Contributor Author

griesemer commented Sep 27, 2021

Agreed that this code should not be permitted because the argument x in the local call of g is of type P (which we don't know anything about) but that call requires the argument to be of type int (per the instantiation of g). In the first recursive call, x will be of type int but that's "too late".

In short, type-checking this function should fail, and thus this is not an issue.

@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants