On 1/14/21 1:49 PM, roger peppe wrote:
This code seems corrupted (no newlines) and incomplete. It's hard to understand what your question is about without seeing the motivational code.

I hate mailing lists for exactly this reason.

Here is the code again:


```

package p1

// S is a type with a parameterized method Identity.
type S struct{}

// Identity is a simple identity method that works for any type.
func (S) Identity[T any](v T) T { return v }

package p2

// HasIdentity is an interface that matches any type with a
// parameterized Identity method.
type HasIdentity interface {
    Identity[T any](T) T
}

package p3

import "p2"

// CheckIdentity checks the Identity method if it exists.
// Note that although this function calls a parameterized method,
// this function is not itself parameterized.
func CheckIdentity(v interface{}) {
    if vi, ok := v.(p2.HasIdentity); ok {
        if got := vi.Identity[int](0); got != 0 {
            panic(got)
        }
    }
}

package p4

import (
    "p1"
    "p3"
)

// CheckSIdentity passes an S value to CheckIdentity.
func CheckSIdentity() {
    p3.CheckIdentity(p1.S{})
}

```


Is there any option to highlight code here?

--
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/e6a9e9df-45d3-f4db-5e36-e37ffe7f08e8%40gmail.com.

Reply via email to