On Friday, January 5, 2024 at 12:59:25 AM UTC-5 Axel Wagner wrote: 3. Someone comes up with a clever new compromise.
Here is a strawman proposal: Allow `Nullable`: type Nullable[T any] struct { T valid bool } By generating a compile error when a developer attempts to use a type as a parameter that would create ambiguity, e.g. throw a compile error on these lines from your examples: var y X[*strings.Reader] And: F[*strings.Reader]() I do recognize that deep call stacks may cause difficulty for this proposal, but my logical reasoning about them (vs. me knowing how it would to be implemented) tells me that `main()` should be able to see the generic type that `F()` requires because `F()` should be able to see the generic type that `G()` requires which is type `X`, and type `X` implements a `Read()` thus making it ambiguous with `*strings.Reader`: type X[T any] struct { T *bufio.Reader } func F[T any]() { G[T]() } func G[T any]() { var x X[T] x.Read } Unless it is effectively not possible to implement that type of logic in the Go compiler because of design decisions — possibly related to compilation performance — then it seems logical the Go compiler should be able to recognize the conflict and generate a compile error on such combinations at the point of passing the type parameter, explicitly or implicitly. While not a perfect solution — since it would disallow edge cases where a developer feels they really must create a struct with both type parameters and use with types that create ambiguity — such a compromise would stop perfect from being the enemy of the good. Anyway, as stated this is a strawman proposal. Please shoot holes in it if there are any opportunities to do so. -Mike -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/eaf71dec-e078-48bd-907c-ed7ff1ada222n%40googlegroups.com.