1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: don't disallow defining methods on interfaces (#8335)

This commit is contained in:
spaceface
2021-01-26 11:56:17 +01:00
committed by GitHub
parent 3959ba5751
commit 5f2b2df546
14 changed files with 77 additions and 50 deletions

View File

@@ -0,0 +1,20 @@
struct Cat {
breed string
}
interface Animal {
breed string
}
fn (a Animal) info() string {
return "I'm a ${a.breed} ${typeof(a).name}"
}
fn new_animal(breed string) Animal {
return &Cat{ breed }
}
fn test_methods_on_interfaces() {
mut a := new_animal('persian')
assert a.info() == "I'm a persian Animal"
}