From 66438e43e1a286f40171825f0236c0cd3df13df6 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Fri, 31 Jan 2025 07:47:39 -0300 Subject: [PATCH] refactor --- vlib/v/gen/c/infix.v | 4 ++-- vlib/v/type_resolver/comptime_resolver.v | 18 ------------------ vlib/v/type_resolver/type_resolver.v | 10 +++++++++- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/vlib/v/gen/c/infix.v b/vlib/v/gen/c/infix.v index 93a5f8dc52c17a..f3a2227f898229 100644 --- a/vlib/v/gen/c/infix.v +++ b/vlib/v/gen/c/infix.v @@ -96,8 +96,8 @@ fn (mut g Gen) infix_expr_arrow_op(node ast.InfixExpr) { // infix_expr_eq_op generates code for `==` and `!=` fn (mut g Gen) infix_expr_eq_op(node ast.InfixExpr) { - left_type := g.type_resolver.get_expr_type_or_default(node.left, node.left_type) - right_type := g.type_resolver.get_expr_type_or_default(node.right, node.right_type) + left_type := g.type_resolver.get_type_or_default(node.left, node.left_type) + right_type := g.type_resolver.get_type_or_default(node.right, node.right_type) left := g.unwrap(left_type) right := g.unwrap(right_type) mut has_defined_eq_operator := false diff --git a/vlib/v/type_resolver/comptime_resolver.v b/vlib/v/type_resolver/comptime_resolver.v index a93f756267fa7f..4a6030e8e5fafc 100644 --- a/vlib/v/type_resolver/comptime_resolver.v +++ b/vlib/v/type_resolver/comptime_resolver.v @@ -110,24 +110,6 @@ pub fn (t &ResolverInfo) get_ct_type_var(node ast.Expr) ast.ComptimeVarKind { return .no_comptime } -// get_expr_type_or_default computes the ast node type regarding its or_expr if its comptime var otherwise default_typ is returned -pub fn (mut t TypeResolver) get_expr_type_or_default(node ast.Expr, default_typ ast.Type) ast.Type { - if !t.info.is_comptime_expr(node) { - return default_typ - } - ctyp := t.get_type(node) - match node { - ast.Ident { - // returns the unwrapped type of the var - if ctyp.has_flag(.option) && node.or_expr.kind != .absent { - return ctyp.clear_flag(.option) - } - } - else {} - } - return if ctyp != ast.void_type { ctyp } else { default_typ } -} - // get_type_from_comptime_var retrives the comptime type related to $for variable @[inline] pub fn (t &TypeResolver) get_type_from_comptime_var(var ast.Ident) ast.Type { diff --git a/vlib/v/type_resolver/type_resolver.v b/vlib/v/type_resolver/type_resolver.v index b4372973a88e05..4d9cb7df31951c 100644 --- a/vlib/v/type_resolver/type_resolver.v +++ b/vlib/v/type_resolver/type_resolver.v @@ -104,7 +104,15 @@ pub fn (mut t TypeResolver) get_type_or_default(node ast.Expr, default_typ ast.T ast.Ident { if node.ct_expr { ctyp := t.get_type(node) - return if ctyp != ast.void_type { ctyp } else { default_typ } + return if ctyp != ast.void_type { + if node.or_expr.kind == .absent { + ctyp + } else { + ctyp.clear_flag(.option) + } + } else { + default_typ + } } } ast.SelectorExpr {