Re: [go-nuts] Re: [generics] some questions

2020-06-18 Thread T L
So, it is really a bug. I will report it. On Thursday, June 18, 2020 at 8:17:22 AM UTC-4, Harald Weidner wrote: > > Hello, > > > But the following code also fails to compile, bug? > > > > package main > > > > type Int interface { > > type int > > } > > > > func Foo(type T Int) ([]T) {

Re: [go-nuts] Re: [generics] some questions

2020-06-18 Thread Harald Weidner
Hello, > But the following code also fails to compile, bug? > > package main > > type Int interface { > type int > } > > func Foo(type T Int) ([]T) {} // undefined: MyInt > > func main() { > type MyInt int > Foo([]MyInt(nil)) > } It compiles if you move "type MyInt int" out of the fun

[go-nuts] Re: [generics] some questions

2020-06-18 Thread T L
It looks, in most cases, the current rules recommends the types shown in the constraint definition must be the elementary types. On Thursday, June 18, 2020 at 7:45:52 AM UTC-4, T L wrote: > It looks the generic type argument must share the underlying type of a > type in the constraint type list

[go-nuts] Re: [generics] some questions

2020-06-18 Thread T L
It looks the generic type argument must share the underlying type of a type in the constraint type list. But the following code also fails to compile, bug? package main type Int interface { type int } func Foo(type T Int) ([]T) {} // undefined: MyInt func main() { type MyInt int F

[go-nuts] Re: [generics] some questions

2020-06-18 Thread T L
Another question, how to make the following code compile: package main type IntSlice interface { type []int } func Foo(type T IntSlice) (T) {} func main() { type MyInt int Foo([]int(nil)) Foo([]MyInt(nil)) // []MyInt does not satisfy IntSlice ([]MyInt not found in []int) } --