ast, checker: make SelectorExpr.root_ident return ?Ident (#9647)

pull/9653/head
Ned Palacios 2021-04-10 00:06:40 +08:00 committed by GitHub
parent b346dd9464
commit 50f59674ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions

View File

@ -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

View File

@ -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
}