Created
July 10, 2012 21:34
-
-
Save danielhfrank/3086385 to your computer and use it in GitHub Desktop.
Go Diamond Problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
// Seems like this could be problematic when extending a type in a 3rd party module... | |
import ( | |
"fmt" | |
) | |
type Shredder interface { | |
Shred() | |
} | |
type Biram struct{} | |
type LeftLane struct{} | |
func (s *Biram) Shred() { | |
fmt.Println("Chicken!") | |
} | |
func (s *LeftLane) Shred() { | |
fmt.Println("Shine!") | |
} | |
type BillHilly struct { | |
Biram | |
LeftLane | |
} | |
func ShredRealLoud(s Shredder) { | |
fmt.Println("!!!!!!!!!!!!!") | |
s.Shred() | |
fmt.Println("!!!!!!!!!!!!!") | |
} | |
func main() { | |
bh := &BillHilly{} | |
bh.Shred() // ./shred.go:35: ambiguous selector bh.Shred | |
ShredRealLoud(bh) // ./shred.go:36: BillHilly.Shred is ambiguous | |
// ./shred.go:36: cannot use bh (type BillHilly) as type Shredder in function argument: | |
// BillHilly does not implement Shredder (missing Shred method) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sure, but it does compile if you comment out either line 25 or 26. I know there's nothing wrong with this behavior, I just found it interesting.