Skip to content

go/types, types2: type inference fails to infer type argument even though correct type is present in argument list #62335

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
griesemer opened this issue Aug 28, 2023 · 2 comments
Assignees
Labels
FrozenDueToAge TypeInference Issue is related to generic type inference

Comments

@griesemer
Copy link
Contributor

package main

type A struct{}
type B struct{}

var a A
var b B
var c struct{}

func main() {
	f(a, b, c) // ERROR "type B of b does not match inferred type A for P"
	f[struct{}](a, b, c)
}

func f[P any](...P) {}

fails to infer the type argument struct{} even though it appears in the function argument list (playground).

This bug existed since Go 1.18.
It partly interferes with a fix for #62157 (we can't fully fix #62157 without addressing this issue as well).

cc: @findleyr

@griesemer griesemer added NeedsFix The path to resolution is known, but the work has not been done. TypeInference Issue is related to generic type inference labels Aug 28, 2023
@griesemer griesemer added this to the Go1.22 milestone Aug 28, 2023
@griesemer griesemer self-assigned this Aug 28, 2023
@griesemer griesemer changed the title go/types, types2: type inference fails to infer underlying type in simple case go/types, types2: type inference fails to infer type argument even though correct type is present in argument list Aug 28, 2023
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/523579 mentions this issue: go/types, types2: use handle struct instead of *Type to track inferred types

@griesemer
Copy link
Contributor Author

Per internal discussion: we're not going to change behavior here. If f(a, c) infers A, f(b, c) infers B, and f(a, b) fails, then f(a, b, c) is ok to fail; i.e., the type argument C must be provided explicitly.

Closing as working as intended.

@griesemer griesemer removed the NeedsFix The path to resolution is known, but the work has not been done. label Aug 29, 2023
@griesemer griesemer removed this from the Go1.22 milestone Aug 29, 2023
@golang golang locked and limited conversation to collaborators Aug 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge TypeInference Issue is related to generic type inference
Projects
None yet
Development

No branches or pull requests

2 participants