From b08690d151343f76cc0e8c33d486cea25e9bf396 Mon Sep 17 00:00:00 2001 From: StunxFS <56417208+StunxFS@users.noreply.github.com> Date: Mon, 1 Aug 2022 04:40:37 -0400 Subject: [PATCH] gen.c: simplify `unwrap_generic` method (#15288) * gen.c: use `nil` instead of `0` * replace `muttable` => `mut_table` --- vlib/v/gen/c/utils.v | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/vlib/v/gen/c/utils.v b/vlib/v/gen/c/utils.v index 79f6bc0a2d..e2513b3d95 100644 --- a/vlib/v/gen/c/utils.v +++ b/vlib/v/gen/c/utils.v @@ -7,22 +7,24 @@ import v.ast fn (mut g Gen) unwrap_generic(typ ast.Type) ast.Type { if typ.has_flag(.generic) { - /* - resolve_generic_to_concrete should not mutate the table. - It mutates if the generic type is for example []T and the - concrete type is an array type that has not been registered - yet. This should have already happened in the checker, since - it also calls 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) } - if t_typ := muttable.resolve_generic_to_concrete(typ, if unsafe { g.cur_fn != 0 } { - g.cur_fn.generic_names - } else { - []string{} - }, g.cur_concrete_types) - { - return t_typ + // NOTE: `resolve_generic_to_concrete` should not mutate the table. + // + // It mutates if the generic type is for example `[]T` and the concrete + // type is an array type that has not been registered yet. + // + // This should have already happened in the checker, since it also calls + // `resolve_generic_to_concrete`. `g.table` is made non-mut to make sure + // no one else can accidentally mutates the table. + unsafe { + 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 + } else { + []string{} + }, g.cur_concrete_types) + { + return t_typ + } } } return typ