1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix other generic pointer cases (#10834)

This commit is contained in:
crthpl 2021-07-17 01:51:42 -07:00 committed by GitHub
parent 51dd8304bb
commit ec47cda386
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 7 deletions

View File

@ -581,7 +581,7 @@ fn (mut g Gen) base_type(t ast.Type) string {
if t.has_flag(.shared_f) {
styp = g.find_or_register_shared(t, styp)
}
nr_muls := t.nr_muls()
nr_muls := g.unwrap_generic(t).nr_muls()
if nr_muls > 0 {
styp += strings.repeat(`*`, nr_muls)
}
@ -596,11 +596,7 @@ fn (mut g Gen) generic_fn_name(types []ast.Type, before string, is_decl bool) st
// `foo<int>()` => `foo_T_int()`
mut name := before + '_T'
for typ in types {
nr_muls := typ.nr_muls()
if is_decl && nr_muls > 0 {
name = strings.repeat(`*`, nr_muls) + name
}
name += '_' + strings.repeat_string('__ptr__', nr_muls) + g.typ(typ.set_nr_muls(0))
name += '_' + strings.repeat_string('__ptr__', typ.nr_muls()) + g.typ(typ.set_nr_muls(0))
}
return name
}

View File

@ -16,7 +16,10 @@ fn test_identity() {
})['a'] == 'b'
assert simple<simplemodule.Data>(simplemodule.Data{ value: 8 }).value == 8
assert simple<&simplemodule.Data>(&simplemodule.Data{ value: 123 }).value == 123
x := &simplemodule.Data{
value: 123
}
assert simple<&simplemodule.Data>(x).value == 123
}
fn plus<T>(xxx T, b T) T {