Nuance in compatibility of type arguments

Can someone please point out why the Android type here is illegal to use where it actually satisfy the comparable interface and it implements the Human interface.

package main

import "fmt"

func main() {
	DoSomething(Person{})

	// DoSomething(OddPerson{}) // Illegal since OddPerson has an underlying type map which is not comparable

	// DoSomething(Dog{}) // Illegal since Dog does not implement Human

	// DoSomething(Android{}) // Illegal, why?
	a1 := Android(1)
	a2 := Android(1)
	fmt.Println(a1 == a2) // Android is comparable here
}

func DoSomething[T Organism](o T) {
	o.Talk()
}

type Organism interface {
	comparable
	Human
}

type Human interface {
	Talk() string
}

type Person struct{}

func (p Person) Talk() string {
	return "I'm a person"
}

type OddPerson map[string]any

func (p OddPerson) Talk() string {
	return "I'm a fake person"
}

type Dog struct{}

func (d Dog) Bark() string {
	return "Woof!"
}

type Android int // Underlying type int for the sake of proving the Human interface

func (a Android) Talk() string {
	return "Hello"
}

The compiler tells you: invalid composite literal type Android
And indeed, Android is not a struct.

You could use DoSomething(Android(0))

1 Like

My bad, I forgot that Android is not a struct on that line. Thanks for pointing out.