cgen: fix generic method receiver typeof name error (#10469)
parent
a0b7e1a0ca
commit
c3b9336f21
|
@ -505,7 +505,7 @@ fn (mut g Gen) call_expr(node ast.CallExpr) {
|
||||||
pub fn (mut g Gen) unwrap_generic(typ ast.Type) ast.Type {
|
pub fn (mut g Gen) unwrap_generic(typ ast.Type) ast.Type {
|
||||||
if typ.has_flag(.generic) {
|
if typ.has_flag(.generic) {
|
||||||
if t_typ := g.table.resolve_generic_to_concrete(typ, g.table.cur_fn.generic_names,
|
if t_typ := g.table.resolve_generic_to_concrete(typ, g.table.cur_fn.generic_names,
|
||||||
g.table.cur_concrete_types, false)
|
g.table.cur_concrete_types, true)
|
||||||
{
|
{
|
||||||
return t_typ
|
return t_typ
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,3 +41,20 @@ fn test_no_paras_generics_fn_typeof_name() {
|
||||||
ret = print_type<bool>()
|
ret = print_type<bool>()
|
||||||
assert ret == 'bool'
|
assert ret == 'bool'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// test generic method receiver typeof name
|
||||||
|
struct Num<T> {
|
||||||
|
num T
|
||||||
|
}
|
||||||
|
|
||||||
|
fn (num Num<T>) test(v T) {
|
||||||
|
println(typeof(num).name)
|
||||||
|
assert typeof(num).name == 'Num<int>'
|
||||||
|
println(typeof(v).name)
|
||||||
|
assert typeof(v).name == 'int'
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_generic_method_receiver_typeof_name() {
|
||||||
|
num := Num<int>{3}
|
||||||
|
num.test(100)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue