Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parser: fix close_scope() missing when field.name is sort, sorted(fix#20436) #20485

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion vlib/v/parser/parser.v
Original file line number Diff line number Diff line change
Expand Up @@ -3315,7 +3315,7 @@ fn (mut p Parser) dot_expr(left ast.Expr) ast.Expr {
next_token: p.tok.kind
}

if is_filter {
if is_filter || field_name == 'sort' || field_name == 'sorted' {
p.close_scope()
}
spytheman marked this conversation as resolved.
Show resolved Hide resolved
return sel_expr
Expand Down
15 changes: 15 additions & 0 deletions vlib/v/tests/selectorexpt_field_name_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// for issue 20436
// phenomenon:
// close_scope() is lost when selectexpr has two special names: sort and sorted.
// This problem can be tested using closure arguments.
struct Foo {
sort []int
}

fn test_main() {
f := Foo{}

fn [f] () {
assert f.sort.len == 0
}()
}
Loading