fix interface methods that return a value
parent
985fb91ee8
commit
7a8e7b4db8
|
@ -389,6 +389,7 @@ fn sort_structs(types []Type) []Type {
|
|||
return types_sorted
|
||||
}
|
||||
|
||||
// Generates interface table and interface indexes
|
||||
fn (v &V) interface_table() string {
|
||||
mut sb := strings.new_builder(100)
|
||||
for _, t in v.table.typesmap {
|
||||
|
|
|
@ -735,7 +735,7 @@ fn (p mut Parser) fn_call(f mut Fn, method_ph int, receiver_var, receiver_type s
|
|||
p.cgen.resetln('')
|
||||
var := p.expr_var.name
|
||||
iname := f.args[0].typ // Speaker
|
||||
p.gen('((void (*)())(${iname}_name_table[${var}._interface_idx][$idx]))(${var}._object)')
|
||||
p.gen('(($f.typ (*)())(${iname}_name_table[${var}._interface_idx][$idx]))(${var}._object)')
|
||||
}
|
||||
}
|
||||
//println('r=$receiver.typ RT=$receiver_type')
|
||||
|
|
|
@ -27,16 +27,18 @@ struct Foo {
|
|||
speaker Speaker
|
||||
}
|
||||
|
||||
fn perform_speak(s Speaker) bool {
|
||||
fn perform_speak(s Speaker) {
|
||||
s.speak()
|
||||
return true
|
||||
assert true
|
||||
name := s.name()
|
||||
assert name == 'Dog' || name == 'Cat'
|
||||
}
|
||||
|
||||
fn test_perform_speak() {
|
||||
d := Dog{}
|
||||
assert perform_speak(d)
|
||||
perform_speak(d)
|
||||
cat := Cat{}
|
||||
assert perform_speak(cat)
|
||||
perform_speak(cat)
|
||||
f := Foo {
|
||||
//speaker: d
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue