1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/compiler/tests/interface_test.v
Alexander Medvednikov cac719c078 []interface
2019-11-08 22:08:02 +03:00

56 lines
711 B
V

struct Dog {
breed string
}
struct Cat {
breed string
}
fn (d Cat) name() string { return 'Cat' }
fn (d Cat) speak() { println('meow') }
fn (d Dog) speak() { println('woof') }
fn (d Dog) name() string { return 'Dog'}
interface Speaker {
name() string
speak()
}
interface Speak2er {
name() string
speak()
}
struct Foo {
speaker Speaker
speakers []Speaker
}
fn perform_speak(s Speaker) {
s.speak()
assert true
name := s.name()
assert name == 'Dog' || name == 'Cat'
}
fn perform_speakers(speakers []Speaker) {
}
fn test_perform_speak() {
dog := Dog{}
perform_speak(dog)
cat := Cat{}
perform_speak(cat)
//perform_speakers([dog, cat])
/*
f := Foo {
speaker: dog
}
*/
}