See code below:
I have an odd behavior that I can't understand in Golang. If I want to create a type alias of a structure and that structure meets the requirements of a interface type, then the type alias won't meet the requirements of that interface type. I have no idea why this is happening. Any thoughts?
package main
import (
"fmt"
)
type MyInt struct {
value int
}
func (m MyInt) DoubleIt() int {
return m.value * 2
}
type MyInter interface {
DoubleIt() int
}
type MyIntContainer struct {
d MyInter
}
type MC MyIntContainer
type MI MyInt
func main() {
e1 := MyIntContainer{MyInt{12}} //This is OK
fmt.Printf("%d
", e1.d.DoubleIt())
e2 := MC{MI{12}} //this fails with error - line 29
fmt.Printf("%d
", e2.d.DoubleIt())
}
The error message: Line 29: cannot use MI literal (type MI) as type MyInter in field value: MI does not implement MyInter (missing DoubleIt method)