gen: fix function with multiple blank params (#8475)

pull/8479/head
Enzo 2021-01-31 15:37:26 +01:00 committed by GitHub
parent f992099726
commit 2945040a67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -239,7 +239,7 @@ fn (mut g Gen) fn_args(args []table.Param, is_variadic bool) ([]string, []string
mut fargs := []string{} mut fargs := []string{}
mut fargtypes := []string{} mut fargtypes := []string{}
for i, arg in args { for i, arg in args {
caname := c_name(arg.name) caname := if arg.name == '_' { g.new_tmp_var() } else { c_name(arg.name) }
typ := g.unwrap_generic(arg.typ) typ := g.unwrap_generic(arg.typ)
arg_type_sym := g.table.get_type_symbol(typ) arg_type_sym := g.table.get_type_symbol(typ)
mut arg_type_name := g.typ(typ) // util.no_dots(arg_type_sym.name) mut arg_type_name := g.typ(typ) // util.no_dots(arg_type_sym.name)

View File

@ -10,6 +10,20 @@ fn test_fn_with_blank_param() {
fn_with_blank_param(321) fn_with_blank_param(321)
} }
fn fn_with_multiple_blank_param(_ int, _ f32) {
_ = 'not an int nor a float'
}
struct Abc {}
fn (_ Abc) fn_with_multiple_blank_param(_ int, _ f32) {}
fn test_fn_with_multiple_blank_param() {
fn_with_multiple_blank_param(1, 1.1)
a := Abc{}
a.fn_with_multiple_blank_param(1, 1.1)
}
fn test_for_in_range() { fn test_for_in_range() {
for _ in 1 .. 10 { for _ in 1 .. 10 {
assert true assert true