checker/cgen: fix mutable generic fn args
parent
8a24d7d723
commit
41dca3ef58
|
@ -1749,7 +1749,7 @@ fn (mut c Checker) stmts(stmts []ast.Stmt) {
|
|||
}
|
||||
|
||||
pub fn (mut c Checker) unwrap_generic(typ table.Type) table.Type {
|
||||
if typ == table.t_type {
|
||||
if typ.idx() == table.t_type_idx {
|
||||
return c.cur_generic_type
|
||||
}
|
||||
return typ
|
||||
|
|
|
@ -315,8 +315,9 @@ fn (mut g Gen) fn_args(args []table.Arg, is_variadic bool) ([]string, []string)
|
|||
no_names := args.len > 0 && args[0].name == 'arg_1'
|
||||
for i, arg in args {
|
||||
caname := c_name(arg.name)
|
||||
arg_type_sym := g.table.get_type_symbol(arg.typ)
|
||||
mut arg_type_name := g.typ(arg.typ) // arg_type_sym.name.replace('.', '__')
|
||||
typ := g.unwrap_generic(arg.typ).set_nr_muls(arg.typ.nr_muls())
|
||||
arg_type_sym := g.table.get_type_symbol(typ)
|
||||
mut arg_type_name := g.typ(typ) // arg_type_sym.name.replace('.', '__')
|
||||
// if arg.name == 'xxx' {
|
||||
// println('! ' + arg_type_name)
|
||||
// }
|
||||
|
@ -400,7 +401,7 @@ fn (mut g Gen) call_expr(node ast.CallExpr) {
|
|||
}
|
||||
|
||||
pub fn (mut g Gen) unwrap_generic(typ table.Type) table.Type {
|
||||
if typ == table.t_type {
|
||||
if typ.idx() == table.t_type_idx {
|
||||
return g.cur_generic_type
|
||||
}
|
||||
return typ
|
||||
|
|
|
@ -371,8 +371,10 @@ fn (mut p Parser) fn_args() ([]table.Arg, bool) {
|
|||
}
|
||||
pos := p.tok.position()
|
||||
mut arg_type := p.parse_type()
|
||||
if is_mut && arg_type != table.t_type {
|
||||
p.check_fn_mutable_arguments(arg_type, pos)
|
||||
if is_mut {
|
||||
if arg_type != table.t_type {
|
||||
p.check_fn_mutable_arguments(arg_type, pos)
|
||||
}
|
||||
// if arg_type.is_ptr() {
|
||||
// p.error('cannot mut')
|
||||
// }
|
||||
|
@ -421,8 +423,10 @@ fn (mut p Parser) fn_args() ([]table.Arg, bool) {
|
|||
}
|
||||
pos := p.tok.position()
|
||||
mut typ := p.parse_type()
|
||||
if is_mut && typ != table.t_type {
|
||||
p.check_fn_mutable_arguments(typ, pos)
|
||||
if is_mut {
|
||||
if typ != table.t_type {
|
||||
p.check_fn_mutable_arguments(typ, pos)
|
||||
}
|
||||
typ = typ.set_nr_muls(1)
|
||||
}
|
||||
if is_variadic {
|
||||
|
|
|
@ -72,7 +72,7 @@ fn test_create() {
|
|||
create<User>()
|
||||
create<City>()
|
||||
u := User{}
|
||||
//gen_arg<User>(mut u)
|
||||
gen_arg<User>(mut u)
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue