ast: fix fn_type_signature for anon functions with alias arguments (#13024)
parent
054bb272df
commit
b94c5c2a9c
|
@ -200,8 +200,13 @@ pub fn (t &Table) fn_type_signature(f &Fn) string {
|
|||
// TODO: for now ignore mut/pts in sig for now
|
||||
typ := arg.typ.set_nr_muls(0)
|
||||
arg_type_sym := t.sym(typ)
|
||||
sig += arg_type_sym.str().to_lower().replace_each(['.', '__', '&', '', '[', 'arr_', 'chan ',
|
||||
'chan_', 'map[', 'map_of_', ']', '_to_', '<', '_T_', ',', '_', ' ', '', '>', ''])
|
||||
if arg_type_sym.kind == .alias {
|
||||
sig += arg_type_sym.cname
|
||||
} else {
|
||||
sig += arg_type_sym.str().to_lower().replace_each(['.', '__', '&', '', '[', 'arr_',
|
||||
'chan ', 'chan_', 'map[', 'map_of_', ']', '_to_', '<', '_T_', ',', '_', ' ', '',
|
||||
'>', ''])
|
||||
}
|
||||
if i < f.params.len - 1 {
|
||||
sig += '_'
|
||||
}
|
||||
|
@ -209,7 +214,11 @@ pub fn (t &Table) fn_type_signature(f &Fn) string {
|
|||
if f.return_type != 0 && f.return_type != void_type {
|
||||
sym := t.sym(f.return_type)
|
||||
opt := if f.return_type.has_flag(.optional) { 'option_' } else { '' }
|
||||
sig += '__$opt$sym.kind'
|
||||
if sym.kind == .alias {
|
||||
sig += '__$opt$sym.cname'
|
||||
} else {
|
||||
sig += '__$opt$sym.kind'
|
||||
}
|
||||
}
|
||||
return sig
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
type MyString = string
|
||||
type MyInt = int
|
||||
|
||||
struct S1 {
|
||||
x fn (a int) MyString
|
||||
}
|
||||
|
||||
struct S2 {
|
||||
y fn (a int) MyInt
|
||||
}
|
||||
|
||||
fn get_string(a int) MyString {
|
||||
return '$a'
|
||||
}
|
||||
|
||||
fn get_int(a int) MyInt {
|
||||
return a
|
||||
}
|
||||
|
||||
fn test_anon_fn_with_alias_args() {
|
||||
s1 := S1{
|
||||
x: get_string
|
||||
}
|
||||
println(s1.x)
|
||||
ret1 := s1.x(22)
|
||||
println(ret1)
|
||||
assert ret1 == '22'
|
||||
|
||||
s2 := S2{
|
||||
y: get_int
|
||||
}
|
||||
println(s2.y)
|
||||
ret2 := s2.y(22)
|
||||
println(ret2)
|
||||
assert ret2 == 22
|
||||
}
|
Loading…
Reference in New Issue