Skip to content

Commit 691a0ad

Browse files
committed
fix12
1 parent 17522d5 commit 691a0ad

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

vlib/v/parser/assign.v

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,12 @@ fn (mut p Parser) check_undefined_variables(names []string, val ast.Expr) ! {
132132
}
133133

134134
fn (mut p Parser) check_cross_variables(exprs []ast.Expr, val ast.Expr) bool {
135-
// NOTE: val_str must be computed before the match, because inside match arms
136-
// `val` gets smartcast to the variant type, and calling .str() on e.g.
137-
// IndexExpr would call the auto-generated struct str() instead of Expr.str().
138-
val_str := val.str()
135+
// NOTE: For IndexExpr and SelectorExpr, we need to compare string representations.
136+
// val_str must be computed before the match, because inside match arms `val` gets
137+
// smartcast to the variant type, and calling .str() on e.g. IndexExpr would call
138+
// the auto-generated struct str() instead of Expr.str().
139+
// Only compute it for the types that actually need it.
140+
val_str := if val is ast.IndexExpr || val is ast.SelectorExpr { val.str() } else { '' }
139141
match val {
140142
ast.Ident {
141143
for expr in exprs {

0 commit comments

Comments
 (0)