Skip to content

Commit

Permalink
cgen: cleanup comptime checks (#23372)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp authored Jan 5, 2025
1 parent 495adc9 commit 43d679b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion vlib/v/gen/c/assign.v
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
g.assign_ct_type = var_type
}
} else if val is ast.InfixExpr && val.op in [.plus, .minus, .mul, .div, .mod]
&& g.comptime.is_comptime(val.left) {
&& val.left_ct_expr {
ctyp := g.unwrap_generic(g.type_resolver.get_type(val.left))
if ctyp != ast.void_type {
ct_type_var := g.comptime.get_ct_type_var(val.left)
Expand Down
1 change: 0 additions & 1 deletion vlib/v/gen/c/str_intp.v
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ fn (mut g Gen) str_val(node ast.StringInterLiteral, i int, fmts []u8) {
}

fn (mut g Gen) string_inter_literal(node ast.StringInterLiteral) {
// fn (mut g Gen) str_int2(node ast.StringInterLiteral) {
inside_interface_deref_old := g.inside_interface_deref
g.inside_interface_deref = true
defer {
Expand Down
4 changes: 2 additions & 2 deletions vlib/v/type_resolver/generic_resolver.v
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ pub fn (mut ct TypeResolver) unwrap_generic_expr(expr ast.Expr, default_typ ast.
return expr.typ
}
ast.InfixExpr {
if ct.info.is_comptime(expr.left) {
if expr.left_ct_expr {
return ct.resolver.unwrap_generic(ct.get_type(expr.left))
}
if ct.info.is_comptime(expr.right) {
if expr.right_ct_expr {
return ct.resolver.unwrap_generic(ct.get_type(expr.right))
}
return default_typ
Expand Down
5 changes: 3 additions & 2 deletions vlib/v/type_resolver/type_resolver.v
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,13 @@ pub fn (mut t TypeResolver) get_type(node ast.Expr) ast.Type {
} else if node is ast.ParExpr && t.info.is_comptime(node.expr) {
return t.get_type(node.expr)
} else if node is ast.InfixExpr {
if !node.left.is_literal() && t.info.is_comptime(node.left) {
if node.left_ct_expr {
return t.get_type(node.left)
} else if !node.right.is_literal() && t.info.is_comptime(node.right) {
} else if node.right_ct_expr {
return t.get_type(node.right)
}
} else if node is ast.CastExpr && node.typ.has_flag(.generic) {
// T(expr)
return t.resolver.unwrap_generic(node.typ)
}
return ast.void_type
Expand Down

0 comments on commit 43d679b

Please sign in to comment.