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

compiler: fix interface bug

This commit is contained in:
yuyi 2020-03-14 21:19:56 +08:00 committed by GitHub
parent 217bbdfd66
commit 8bfa7f0d82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 8 deletions

View File

@ -839,9 +839,15 @@ fn (p mut Parser) fn_call(f mut Fn, method_ph int, receiver_var, receiver_type s
idx = i
}
}
p.cgen.resetln('')
var := p.expr_var.name
iname := f.args[0].typ // Speaker
// remove useless var
if p.cgen.is_tmp {
p.cgen.tmp_line = p.cgen.tmp_line.replace(' $var', '')
}
else {
p.cgen.cur_line = p.cgen.cur_line.replace(' $var', '')
}
p.gen('(($f.typ (*)())(${iname}_name_table[${var}._interface_idx][$idx]))(${var}._object')
receiver_is_interface = true
}

View File

@ -26,18 +26,19 @@ interface Speak2er {
struct Foo {
speaker Speaker
speakers []Speaker
}
}
fn perform_speak(s Speaker) {
s.speak()
assert true
name := s.name()
assert name == 'Dog' || name == 'Cat'
println(s.name())
}
fn perform_speakers(speakers []Speaker) {
}
}
fn test_perform_speak() {
dog := Dog{}
@ -48,7 +49,7 @@ fn test_perform_speak() {
/*
f := Foo {
speaker: dog
}
}
*/
}
@ -70,6 +71,3 @@ fn test_register() {
f.register()
handle_reg(f)
}