cgen: fix generic method receiver typeof name error (#10469)

pull/10477/head
yuyi 2021-06-16 09:03:50 +08:00 committed by GitHub
parent a0b7e1a0ca
commit c3b9336f21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -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 {
if typ.has_flag(.generic) {
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
}

View File

@ -41,3 +41,20 @@ fn test_no_paras_generics_fn_typeof_name() {
ret = print_type<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)
}