@@ -4312,7 +4312,9 @@ fn (mut c Checker) smartcast(mut expr ast.Expr, cur_type ast.Type, to_type_ ast.
43124312 mut orig_type := 0
43134313 mut is_inherited := false
43144314 mut ct_type_var := ast.ComptimeVarKind.no_comptime
4315+ mut is_ct_type_unwrapped := false
43154316 if mut expr.obj is ast.Var {
4317+ is_ct_type_unwrapped = expr.obj.ct_type_var != ast.ComptimeVarKind.no_comptime
43164318 is_mut = expr.obj.is_mut
43174319 smartcasts << expr.obj.smartcasts
43184320 is_already_casted = expr.obj.pos.pos == expr.pos.pos
@@ -4334,16 +4336,17 @@ fn (mut c Checker) smartcast(mut expr ast.Expr, cur_type ast.Type, to_type_ ast.
43344336 if cur_type.has_flag (.option) && ! to_type.has_flag (.option) {
43354337 if ! var.is_unwrapped {
43364338 scope.register (ast.Var{
4337- name: expr.name
4338- typ: cur_type
4339- pos: expr.pos
4340- is_used: true
4341- is_mut: expr.is_mut
4342- is_inherited: is_inherited
4343- smartcasts: [to_type]
4344- orig_type: orig_type
4345- ct_type_var: ct_type_var
4346- is_unwrapped: true
4339+ name: expr.name
4340+ typ: cur_type
4341+ pos: expr.pos
4342+ is_used: true
4343+ is_mut: expr.is_mut
4344+ is_inherited: is_inherited
4345+ smartcasts: [to_type]
4346+ orig_type: orig_type
4347+ ct_type_var: ct_type_var
4348+ ct_type_unwrapped: is_ct_type_unwrapped
4349+ is_unwrapped: true
43474350 })
43484351 } else {
43494352 scope.update_smartcasts (expr.name, to_type, true )
@@ -4355,16 +4358,17 @@ fn (mut c Checker) smartcast(mut expr ast.Expr, cur_type ast.Type, to_type_ ast.
43554358 }
43564359 }
43574360 scope.register (ast.Var{
4358- name: expr.name
4359- typ: cur_type
4360- pos: expr.pos
4361- is_used: true
4362- is_mut: expr.is_mut
4363- is_inherited: is_inherited
4364- is_unwrapped: is_option_unwrap
4365- smartcasts: smartcasts
4366- orig_type: orig_type
4367- ct_type_var: ct_type_var
4361+ name: expr.name
4362+ typ: cur_type
4363+ pos: expr.pos
4364+ is_used: true
4365+ is_mut: expr.is_mut
4366+ is_inherited: is_inherited
4367+ is_unwrapped: is_option_unwrap
4368+ smartcasts: smartcasts
4369+ orig_type: orig_type
4370+ ct_type_var: ct_type_var
4371+ ct_type_unwrapped: is_ct_type_unwrapped
43684372 })
43694373 } else if is_mut && ! expr.is_mut {
43704374 c.smartcast_mut_pos = expr.pos
0 commit comments