Support index expressions and selectors in range loops #1053

Open
opened 2025-12-28 17:15:04 +00:00 by sami · 0 comments
Owner

Originally created by @roman-khimov on GitHub (Jan 11, 2023).

This won't work with the compiler we have:

ints := []int{5, 4, 3, 2, 1}
for ints[0] = range ints {
        break
}
return ints[0]

Right now that'd be

panic: interface conversion: ast.Expr is *ast.IndexExpr, not *ast.Ident [recovered]
        panic: interface conversion: ast.Expr is *ast.IndexExpr, not *ast.Ident

It'll be a bit more gentle error soon, but properly fixing this requires some refactoring of *ast.AssignStmt handler and that's not what I'd like to do right now for this very specific case.

Originally created by @roman-khimov on GitHub (Jan 11, 2023). This won't work with the compiler we have: ``` ints := []int{5, 4, 3, 2, 1} for ints[0] = range ints { break } return ints[0] ``` Right now that'd be ``` panic: interface conversion: ast.Expr is *ast.IndexExpr, not *ast.Ident [recovered] panic: interface conversion: ast.Expr is *ast.IndexExpr, not *ast.Ident ``` It'll be a bit more gentle error soon, but properly fixing this requires some refactoring of `*ast.AssignStmt` handler and that's not what I'd like to do right now for this very specific case.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
nspcc-dev/neo-go#1053
No description provided.