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

interface: enable calling interface with multi-args

This commit is contained in:
cloudsong 2019-11-19 23:27:32 +08:00 committed by Alexander Medvednikov
parent 4bbed4f910
commit 787f49b7a0

View File

@ -722,6 +722,8 @@ fn (p mut Parser) fn_call(f mut Fn, method_ph int, receiver_var, receiver_type s
// we need to preappend "method(receiver, ...)"
if f.is_method {
receiver := f.args.first()
mut receiver_is_interface := false
if receiver.typ.ends_with('er') {
// I absolutely love this syntax
// `s.speak()` =>
@ -740,7 +742,8 @@ 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('(($f.typ (*)())(${iname}_name_table[${var}._interface_idx][$idx]))(${var}._object)')
p.gen('(($f.typ (*)())(${iname}_name_table[${var}._interface_idx][$idx]))(${var}._object')
receiver_is_interface = true
}
}
//println('r=$receiver.typ RT=$receiver_type')
@ -756,7 +759,10 @@ fn (p mut Parser) fn_call(f mut Fn, method_ph int, receiver_var, receiver_type s
if !p.expr_var.is_changed && receiver.is_mut {
p.mark_var_changed(p.expr_var)
}
p.gen_method_call(receiver, receiver_type, cgen_name, f.typ, method_ph)
if !receiver_is_interface {
p.gen_method_call(receiver, receiver_type, cgen_name, f.typ, method_ph)
}
} else {
// Normal function call
p.gen('$cgen_name (')