Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Jan 24, 2025
1 parent abf425b commit 898681a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion vlib/v/gen/c/cgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -3661,7 +3661,7 @@ fn (mut g Gen) expr(node_ ast.Expr) {
} else if mut node.expr is ast.Ident && node.expr.ct_expr {
// val?
expr_str = node.expr.name
is_unwrapped = g.type_resolver.get_type(node.expr).has_flag(.option)
is_unwrapped = !g.inside_assign
}
g.writeln('if (${expr_str}.state != 0) {')
g.writeln2('\tpanic_option_not_set(_SLIT("none"));', '}')
Expand Down
5 changes: 5 additions & 0 deletions vlib/v/type_resolver/comptime_resolver.v
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub fn (t &ResolverInfo) is_comptime_expr(node ast.Expr) bool {
return (node is ast.Ident && node.ct_expr)
|| (node is ast.IndexExpr && t.is_comptime_expr(node.left))
|| node is ast.ComptimeSelector
|| (node is ast.PostfixExpr && t.is_comptime_expr(node.expr))
}

// has_comptime_expr checks if the expr contains some comptime expr
Expand All @@ -27,6 +28,7 @@ pub fn (t &ResolverInfo) has_comptime_expr(node ast.Expr) bool {
return (node is ast.Ident && node.ct_expr)
|| (node is ast.IndexExpr && t.has_comptime_expr(node.left))
|| node is ast.ComptimeSelector
|| (node is ast.PostfixExpr && t.has_comptime_expr(node.expr))
|| (node is ast.SelectorExpr && t.has_comptime_expr(node.expr))
|| (node is ast.InfixExpr && (t.has_comptime_expr(node.left)
|| t.has_comptime_expr(node.right)))
Expand Down Expand Up @@ -58,6 +60,9 @@ pub fn (t &ResolverInfo) is_comptime(node ast.Expr) bool {
ast.ComptimeSelector {
return true
}
ast.PostfixExpr {
return t.is_comptime(node.expr)
}
else {
false
}
Expand Down
4 changes: 3 additions & 1 deletion vlib/v/type_resolver/type_resolver.v
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ pub fn (mut t TypeResolver) get_type(node ast.Expr) ast.Type {
// T(expr)
return t.resolver.unwrap_generic(node.typ)
} else if node is ast.PostfixExpr && node.op == .question
&& (node.expr is ast.Ident && node.expr.ct_expr) {
&& node.expr in [ast.Ident, ast.ComptimeSelector] {
// var?
// f.$(field.name)?
ctyp := t.get_type(node.expr)
return ctyp.clear_flag(.option)
}
Expand Down

0 comments on commit 898681a

Please sign in to comment.