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

gen.c: simplify unwrap_generic method (#15288)

* gen.c: use `nil` instead of `0`
* replace `muttable` => `mut_table`
This commit is contained in:
StunxFS 2022-08-01 04:40:37 -04:00 committed by GitHub
parent b4fd9b5f92
commit b08690d151
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,16 +7,17 @@ import v.ast
fn (mut g Gen) unwrap_generic(typ ast.Type) ast.Type { fn (mut g Gen) unwrap_generic(typ ast.Type) ast.Type {
if typ.has_flag(.generic) { if typ.has_flag(.generic) {
/* // NOTE: `resolve_generic_to_concrete` should not mutate the table.
resolve_generic_to_concrete should not mutate the table. //
It mutates if the generic type is for example []T and the // It mutates if the generic type is for example `[]T` and the concrete
concrete type is an array type that has not been registered // type is an array type that has not been registered yet.
yet. This should have already happened in the checker, since //
it also calls resolve_generic_to_concrete. g.table is made // This should have already happened in the checker, since it also calls
non-mut to make sure no one else can accidentally mutates the table. // `resolve_generic_to_concrete`. `g.table` is made non-mut to make sure
*/ // no one else can accidentally mutates the table.
mut muttable := unsafe { &ast.Table(g.table) } unsafe {
if t_typ := muttable.resolve_generic_to_concrete(typ, if unsafe { g.cur_fn != 0 } { mut mut_table := &ast.Table(g.table)
if t_typ := mut_table.resolve_generic_to_concrete(typ, if g.cur_fn != nil {
g.cur_fn.generic_names g.cur_fn.generic_names
} else { } else {
[]string{} []string{}
@ -25,6 +26,7 @@ fn (mut g Gen) unwrap_generic(typ ast.Type) ast.Type {
return t_typ return t_typ
} }
} }
}
return typ return typ
} }