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) {
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
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
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
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)
}
--