Hi
Is there a way to constrain one parameter to be assignable to another?
For example, in ye olde days, I'd have:
type Iface interface {
// ...
}
type Concrete1 struct { /* ... */ }
var _ Iface = &Concrete1{}
type Concrete2 struct{ /* ... */ }
var _ Iface = &Concrete2{}
// Repeat ad nauseam
Now, I'm finding myself wanting similar compile time checks for generic types and functions. E.g.
func foo[Iface any, Concrete Iface]() {
var c Concrete
var _ Iface = c
}
Obviously that's a bit contrived, but I'm writing code that needs both the concrete type (*someStruct) and the interface it's meant to adhere to.
The above code does not compile with 1.18 (cannot use a type parameter as constraint)
I have a runtime check that works, but I'd love a compile time check. Is there a way to do that?
Thanks
Michael