Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Jan 26, 2025
1 parent 3343fb7 commit 4bd651c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
44 changes: 24 additions & 20 deletions vlib/v/checker/checker.v
Original file line number Diff line number Diff line change
Expand Up @@ -4312,7 +4312,9 @@ fn (mut c Checker) smartcast(mut expr ast.Expr, cur_type ast.Type, to_type_ ast.
mut orig_type := 0
mut is_inherited := false
mut ct_type_var := ast.ComptimeVarKind.no_comptime
mut is_ct_type_unwrapped := false
if mut expr.obj is ast.Var {
is_ct_type_unwrapped = expr.obj.ct_type_var != ast.ComptimeVarKind.no_comptime
is_mut = expr.obj.is_mut
smartcasts << expr.obj.smartcasts
is_already_casted = expr.obj.pos.pos == expr.pos.pos
Expand All @@ -4334,16 +4336,17 @@ fn (mut c Checker) smartcast(mut expr ast.Expr, cur_type ast.Type, to_type_ ast.
if cur_type.has_flag(.option) && !to_type.has_flag(.option) {
if !var.is_unwrapped {
scope.register(ast.Var{
name: expr.name
typ: cur_type
pos: expr.pos
is_used: true
is_mut: expr.is_mut
is_inherited: is_inherited
smartcasts: [to_type]
orig_type: orig_type
ct_type_var: ct_type_var
is_unwrapped: true
name: expr.name
typ: cur_type
pos: expr.pos
is_used: true
is_mut: expr.is_mut
is_inherited: is_inherited
smartcasts: [to_type]
orig_type: orig_type
ct_type_var: ct_type_var
ct_type_unwrapped: is_ct_type_unwrapped
is_unwrapped: true
})
} else {
scope.update_smartcasts(expr.name, to_type, true)
Expand All @@ -4355,16 +4358,17 @@ fn (mut c Checker) smartcast(mut expr ast.Expr, cur_type ast.Type, to_type_ ast.
}
}
scope.register(ast.Var{
name: expr.name
typ: cur_type
pos: expr.pos
is_used: true
is_mut: expr.is_mut
is_inherited: is_inherited
is_unwrapped: is_option_unwrap
smartcasts: smartcasts
orig_type: orig_type
ct_type_var: ct_type_var
name: expr.name
typ: cur_type
pos: expr.pos
is_used: true
is_mut: expr.is_mut
is_inherited: is_inherited
is_unwrapped: is_option_unwrap
smartcasts: smartcasts
orig_type: orig_type
ct_type_var: ct_type_var
ct_type_unwrapped: is_ct_type_unwrapped
})
} else if is_mut && !expr.is_mut {
c.smartcast_mut_pos = expr.pos
Expand Down
3 changes: 2 additions & 1 deletion vlib/v/gen/c/cgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -5158,7 +5158,8 @@ fn (mut g Gen) ident(node ast.Ident) {
}
}
if i == 0 && node.obj.ct_type_var != .smartcast && node.obj.is_unwrapped {
dot := if !node.obj.orig_type.is_ptr() && obj_sym.is_heap() {
dot := if !node.obj.ct_type_unwrapped && !node.obj.orig_type.is_ptr()
&& obj_sym.is_heap() {
'->'
} else {
'.'
Expand Down

0 comments on commit 4bd651c

Please sign in to comment.