diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 33a18a3828..d7fc8cfcfc 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -3429,7 +3429,8 @@ _Interface I_${cctype}_to_Interface(${cctype}* x) { }; }') methods_struct.writeln('\t{') - for method in ityp.methods { + st_sym := g.table.get_type_symbol(st) + for method in st_sym.methods { // .speak = Cat_speak mut method_call := '${cctype}_${method.name}' if !method.args[0].typ.is_ptr() { diff --git a/vlib/v/tests/interface_test.v b/vlib/v/tests/interface_test.v index 07a820b320..2618d2b9bd 100644 --- a/vlib/v/tests/interface_test.v +++ b/vlib/v/tests/interface_test.v @@ -7,11 +7,13 @@ struct Cat { breed string } -fn (d Cat) name() string { +fn (mut c Cat) name() string { + assert c.breed == 'Persian' return 'Cat' } -fn (d Cat) speak(s string) { +fn (c &Cat) speak(s string) { + assert c.breed == 'Persian' assert s == 'Hi !' println('meow') } @@ -32,7 +34,6 @@ fn test_todo() { else{} } - fn perform_speak(s Animal) { s.speak('Hi !') assert true @@ -47,9 +48,9 @@ fn perform_speak(s Animal) { fn test_perform_speak() { dog := Dog{breed: 'Labrador Retriever'} perform_speak(dog) - cat := Cat{} + cat := Cat{breed: 'Persian'} perform_speak(cat) - perform_speak(Cat{}) + perform_speak(Cat{breed: 'Persian'}) handle_animals([dog, cat]) /* f := Foo { @@ -94,7 +95,6 @@ interface Animal { speak(s string) } - fn test_interface_array() { mut animals := []Animal{} animals = [ Cat{}, Dog{} ]