ast, checker: make SelectorExpr.root_ident return ?Ident (#9647)
parent
b346dd9464
commit
50f59674ce
|
@ -149,14 +149,18 @@ pub mut:
|
|||
}
|
||||
|
||||
// root_ident returns the origin ident where the selector started.
|
||||
pub fn (e &SelectorExpr) root_ident() Ident {
|
||||
pub fn (e &SelectorExpr) root_ident() ?Ident {
|
||||
mut root := e.expr
|
||||
for root is SelectorExpr {
|
||||
// TODO: remove this line
|
||||
selector_expr := root as SelectorExpr
|
||||
root = selector_expr.expr
|
||||
}
|
||||
if root is Ident {
|
||||
return root as Ident
|
||||
}
|
||||
|
||||
return none
|
||||
}
|
||||
|
||||
// module declaration
|
||||
|
|
|
@ -5116,11 +5116,12 @@ fn (c Checker) smartcast(expr ast.Expr, cur_type ast.Type, to_type_ ast.Type, mu
|
|||
mut orig_type := 0
|
||||
if field := c.table.find_field(expr_sym, expr.field_name) {
|
||||
if field.is_mut {
|
||||
root_ident := expr.root_ident()
|
||||
if root_ident := expr.root_ident() {
|
||||
if v := scope.find_var(root_ident.name) {
|
||||
is_mut = v.is_mut
|
||||
}
|
||||
}
|
||||
}
|
||||
if orig_type == 0 {
|
||||
orig_type = field.typ
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue