Skip to content

Commit 4f17ee4

Browse files
authored
Merge pull request #158 from gnikit:gnikit/issue157
Erroneous diagnostic error with "recursive" argument in arg list
2 parents a703bfd + 4ecc4ce commit 4f17ee4

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
## Unreleased
44

5+
## 2.11.0
6+
7+
### Fixed
8+
9+
- Fixed bug thorowing diagnostic errors if arguments were named `pure`, `elemental`, etc.
10+
([#157](https://github.com/gnikit/fortls/issues/157))
11+
512
## 2.10.0
613

714
### Fixed

fortls/regex_patterns.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ class FortranRegularExpressions:
1515
INCLUDE: Pattern = compile(r"[ ]*INCLUDE[ :]*[\'\"]([^\'\"]*)", I)
1616
CONTAINS: Pattern = compile(r"[ ]*(CONTAINS)[ ]*$", I)
1717
IMPLICIT: Pattern = compile(r"[ ]*IMPLICIT[ ]+([a-z]*)", I)
18-
SUB_MOD: Pattern = compile(r"[ ]*\b(PURE|IMPURE|ELEMENTAL|RECURSIVE)\b", I)
18+
#: Parse procedure keywords but not if they start with , or ( or end with , or )
19+
#: This is to avoid parsing as keywords variables named pure, impure, etc.
20+
SUB_MOD: Pattern = compile(
21+
r"[ ]*(?!<[,\()][ ]*)\b(PURE|IMPURE|ELEMENTAL|RECURSIVE)\b(?![,\)][ ]*)", I
22+
)
1923
SUB: Pattern = compile(r"[ ]*SUBROUTINE[ ]+(\w+)", I)
2024
END_SUB: Pattern = compile(r"SUBROUTINE", I)
2125
FUN: Pattern = compile(r"[ ]*FUNCTION[ ]+(\w+)", I)

test/test_server_diagnostics.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,3 +404,15 @@ def test_submodule_scopes():
404404
errcode, results = run_request(string, ["-n", "1"])
405405
assert errcode == 0
406406
assert results[1]["diagnostics"] == []
407+
408+
409+
def test_keyword_arg_list_var_names():
410+
"""Test argument list variables named as keywords are correctly parsed."""
411+
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir / "diag")})
412+
file_path = str(test_dir / "diag" / "test_function_arg_list.f90")
413+
string += write_rpc_notification(
414+
"textDocument/didOpen", {"textDocument": {"uri": file_path}}
415+
)
416+
errcode, results = run_request(string, ["-n", "1"])
417+
assert errcode == 0
418+
assert results[1]["diagnostics"] == []
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
program test_arg_names_as_keywords
2+
implicit none
3+
integer, parameter :: impure = 8
4+
contains
5+
subroutine foo(recursive, ierr)
6+
integer, intent(in) :: recursive
7+
integer, intent(out) :: ierr
8+
print*, recursive
9+
end subroutine foo
10+
real(8) impure elemental function foo2(recursive, elemental) result(pure)
11+
integer, intent(in) :: recursive, elemental
12+
end function foo2
13+
real( kind = impure ) pure elemental function foo3(recursive) result(pure)
14+
integer, intent(in) :: recursive
15+
end function foo3
16+
subroutine foo4(&
17+
recursive, &
18+
ierr)
19+
integer, intent(in) :: recursive
20+
integer, intent(out) :: ierr
21+
print*, recursive
22+
end subroutine foo4
23+
pure real(impure) function foo5(recursive) result(val)
24+
integer, intent(in) :: recursive
25+
end function foo5
26+
end program test_arg_names_as_keywords

0 commit comments

Comments
 (0)