-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Closed
Labels
DocumentationIssues describing a change to documentation.Issues describing a change to documentation.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.TypeInferenceIssue is related to generic type inferenceIssue is related to generic type inferencecompiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Milestone
Description
Edit: See #53650 (comment) for a summary of the problem.
What version of Go are you using (go version)?
$ go version go version go1.18.3 windows/amd64
What did you do?
type BaseT interface {
Type1 | Type2
}
type BaseType int
type Type1 BaseType
type Type2 BaseType // float64
type ValueT[T BaseT] struct {
A1 T
}
func NewType1() *ValueT[Type1] {
r := NewT[Type1]()
return r
}
func NewType2() *ValueT[Type2] {
r := NewT[Type2]()
return r
}
func NewT[TBase BaseT, TVal ValueT[TBase]]() *TVal {
ret := TVal{}
return &ret
}
func TestGoType(t *testing.T) {
r1 := NewType1()
r2 := NewType2()
t.Log(r1, r2)
t.Log(reflect.TypeOf(r1), reflect.TypeOf(r2))
fooT1(r1.A1)
fooT2(r2.A1)
}
func fooT1(t1 Type1) {
}
func fooT2(t2 Type2) {
}What did you expect to see?
Compile success
What did you see instead?
error:
TBase does not match int
TBase does not match int
Metadata
Metadata
Assignees
Labels
DocumentationIssues describing a change to documentation.Issues describing a change to documentation.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.TypeInferenceIssue is related to generic type inferenceIssue is related to generic type inferencecompiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.