gen: fix multiple blank param with interface (#8480)

pull/8477/head
Enzo 2021-01-31 18:44:55 +01:00 committed by GitHub
parent effa3188dd
commit 778b83a132
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 10 deletions

View File

@ -6016,22 +6016,22 @@ $staticprefix $interface_name* I_${cctype}_to_Interface_${interface_name}_ptr($c
// inline void Cat_speak_method_wrapper(Cat c) { return Cat_speak(*c); } // inline void Cat_speak_method_wrapper(Cat c) { return Cat_speak(*c); }
methods_wrapper.write('static inline ${g.typ(method.return_type)}') methods_wrapper.write('static inline ${g.typ(method.return_type)}')
methods_wrapper.write(' ${method_call}_method_wrapper(') methods_wrapper.write(' ${method_call}_method_wrapper(')
methods_wrapper.write('$cctype* ${method.params[0].name}') //
// TODO g.fn_args params_start_pos := g.out.len
for j in 1 .. method.params.len { mut params := method.params.clone()
arg := method.params[j] first_param := params[0] // workaround, { params[0] | ... } doesn't work
methods_wrapper.write(', ${g.typ(arg.typ)} $arg.name') params[0] = {
first_param |
typ: params[0].typ.set_nr_muls(1)
} }
fargs, _ := g.fn_args(params, false) // second argument is ignored anyway
methods_wrapper.write(g.out.cut_last(g.out.len - params_start_pos))
methods_wrapper.writeln(') {') methods_wrapper.writeln(') {')
methods_wrapper.write('\t') methods_wrapper.write('\t')
if method.return_type != table.void_type { if method.return_type != table.void_type {
methods_wrapper.write('return ') methods_wrapper.write('return ')
} }
methods_wrapper.write('${method_call}(*${method.params[0].name}') methods_wrapper.writeln('${method_call}(*${fargs.join(', ')});')
for j in 1 .. method.params.len {
methods_wrapper.write(', ${method.params[j].name}')
}
methods_wrapper.writeln(');')
methods_wrapper.writeln('}') methods_wrapper.writeln('}')
// .speak = Cat_speak_method_wrapper // .speak = Cat_speak_method_wrapper
method_call += '_method_wrapper' method_call += '_method_wrapper'

View File

@ -14,6 +14,10 @@ fn fn_with_multiple_blank_param(_ int, _ f32) {
_ = 'not an int nor a float' _ = 'not an int nor a float'
} }
interface Foo {
fn_with_multiple_blank_param(int, f32)
}
struct Abc {} struct Abc {}
fn (_ Abc) fn_with_multiple_blank_param(_ int, _ f32) {} fn (_ Abc) fn_with_multiple_blank_param(_ int, _ f32) {}
@ -24,6 +28,14 @@ fn test_fn_with_multiple_blank_param() {
a.fn_with_multiple_blank_param(1, 1.1) a.fn_with_multiple_blank_param(1, 1.1)
} }
fn call_fn_with_multiple_blank_param(foo Foo) {
foo.fn_with_multiple_blank_param(1, 1.1)
}
fn test_interface_fn_with_multiple_blank_param() {
call_fn_with_multiple_blank_param(Abc{})
}
fn test_for_in_range() { fn test_for_in_range() {
for _ in 1 .. 10 { for _ in 1 .. 10 {
assert true assert true