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:
20
vlib/v/tests/methods_on_interfaces_test.v
Normal file
20
vlib/v/tests/methods_on_interfaces_test.v
Normal 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"
|
||||
}
|
||||
Reference in New Issue
Block a user