Skip to content

Commit aa055e5

Browse files
authored
fix: prevent parser crash when using 'it' as variable name (fix #157, fix #156) (#158)
1 parent 26c2c4c commit aa055e5

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/analyzer/psi/utils.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub fn get_it_call(element PsiElement) ?&CallExpression {
1919
methods_names := ['filter', 'map', 'any', 'all']
2020
if mut parent_call is CallExpression {
2121
for !is_array_method_call(*parent_call, ...methods_names) {
22-
parent_call = parent_call.parent_of_type(.call_expression) or { break }
22+
return none
2323
}
2424
}
2525

src/tests/definitions.v

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,23 @@ fn definitions() testing.Tester {
213213
t.assert_definition_name(first, 'name')!
214214
})
215215

216+
t.test('it as function parameter', fn (mut t testing.Test, mut fixture testing.Fixture) ! {
217+
fixture.configure_by_text('1.v', "
218+
fn foo(it int) {
219+
if i/*caret*/t.str() == 1 {
220+
println('one')
221+
}
222+
}
223+
".trim_indent())!
224+
225+
locations := fixture.definition_at_cursor()
226+
t.assert_has_definition(locations)!
227+
228+
first := locations.first()
229+
t.assert_uri(first.target_uri, fixture.current_file_uri())!
230+
t.assert_definition_name(first, 'it')!
231+
})
232+
216233
t.slow_test('shell script implicit os module', fn (mut t testing.Test, mut fixture testing.Fixture) ! {
217234
fixture.configure_by_text('1.vsh', '
218235
abs_/*caret*/path()

0 commit comments

Comments
 (0)