-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Closed
Labels
FeatureRequestIssues asking for a new feature that does not need a proposal.Issues asking for a new feature that does not need a proposal.FrozenDueToAgeNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.Feedback is required from experts, contributors, and/or the community before a change can be made.TypeInferenceIssue is related to generic type inferenceIssue is related to generic type inference
Milestone
Description
commit 8ea0120
The type inference algorithm does not work when the actual parameter is a concrete type and the formal parameter is a generic interface type. It looks like the type inference description in the proposal doesn't cover interfaces, but I suspect it should.
https://go2goplay.golang.org/p/C53vOfwA9vq
package main
type S struct {}
func (S) M() byte {
return 0
}
type I[T any] interface {
M() T
}
func F[T any](x I[T]) {
x.M()
}
func main() {
F(S{})
}
This fails with the error:
prog.go2:18:4: type S of (S literal) does not match I[T] (cannot infer T)
FWIW type interfence doesn't work when the interface argument is a type parameter either, but I can't work out if that's covered by the proposal or not: https://go2goplay.golang.org/p/pAouk3xkmOX
func F[X I[T], T any](x X) {
x.M()
}
bcmills, firelizzard18, RussellLuo, ajwerner, tmr232 and 22 more
Metadata
Metadata
Assignees
Labels
FeatureRequestIssues asking for a new feature that does not need a proposal.Issues asking for a new feature that does not need a proposal.FrozenDueToAgeNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.Feedback is required from experts, contributors, and/or the community before a change can be made.TypeInferenceIssue is related to generic type inferenceIssue is related to generic type inference