Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Jan 31, 2025
1 parent 78effd0 commit 66438e4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
4 changes: 2 additions & 2 deletions vlib/v/gen/c/infix.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 0 additions & 18 deletions vlib/v/type_resolver/comptime_resolver.v
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 9 additions & 1 deletion vlib/v/type_resolver/type_resolver.v
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 66438e4

Please sign in to comment.