Skip to content

Commit 18ec208

Browse files
committed
Fixes END FORALL end of scope error
Case select with forall causes unexpected end of scope #18
1 parent 5ff78b0 commit 18ec208

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
([gnikit/fortls#13](https://github.com/gnikit/fortls/issues/13))
3737
- `POINTER` attribute now displays upon hover
3838
([gnikit/fortls#16](https://github.com/gnikit/fortls/issues/16))
39+
- Fixes `END FORALL` end of scope error
40+
([gnikit/fortls#18](https://github.com/gnikit/fortls/issues/18))
3941

4042
## 1.16.0
4143

fortls/regex_patterns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
END_WORD_REGEX = re.compile(
4949
r"[ ]*END[ ]*(DO|WHERE|IF|BLOCK|ASSOCIATE|SELECT"
5050
r"|TYPE|ENUM|MODULE|SUBMODULE|PROGRAM|INTERFACE"
51-
r"|SUBROUTINE|FUNCTION|PROCEDURE)?([ ]+(?!\W)|$)",
51+
r"|SUBROUTINE|FUNCTION|PROCEDURE|FORALL)?([ ]+(?!\W)|$)",
5252
re.I,
5353
)
5454
TYPE_DEF_REGEX = re.compile(r"[ ]*(TYPE)[, :]+", re.I)

test/test_server.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ def check_return(result_array):
178178
["test", 6, 7],
179179
["test_abstract", 2, 0],
180180
["test_external", 2, 0],
181+
["test_forall", 2, 0],
181182
["test_free", 2, 0],
182183
["test_gen_type", 5, 1],
183184
["test_generic", 2, 0],
@@ -603,6 +604,7 @@ def test_diagnostics():
603604

604605
def check_return(results, ref_results):
605606
for i, r in enumerate(results):
607+
print(r["diagnostics"], ref_results[i])
606608
assert r["diagnostics"] == ref_results[i]
607609

608610
string = write_rpc_request(1, "initialize", {"rootPath": test_dir})
@@ -633,8 +635,15 @@ def check_return(results, ref_results):
633635
string += write_rpc_notification(
634636
"textDocument/didOpen", {"textDocument": {"uri": file_path}}
635637
)
638+
# Checks that forall with end forall inside a case select does not cause
639+
# unexpected end of scope.
640+
file_path = os.path.join(test_dir, "diag", "test_forall.f90")
641+
string += write_rpc_notification(
642+
"textDocument/didOpen", {"textDocument": {"uri": file_path}}
643+
)
636644
errcode, results = run_request(string)
637645
assert errcode == 0
646+
file_path = os.path.join(test_dir, "diag", "test_external.f90")
638647
ref_results = [
639648
[],
640649
[],
@@ -682,6 +691,7 @@ def check_return(results, ref_results):
682691
],
683692
},
684693
],
694+
[],
685695
]
686696
check_return(results[1:], ref_results)
687697

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
program test_forall
2+
implicit none
3+
integer :: i, j, dim=3, a(10) = 2
4+
5+
select case (dim)
6+
case(3)
7+
forall(i=1:10)
8+
a(i) = a(i) **2
9+
forall (j=1:i) a(j) = a(j) ** 2
10+
end forall
11+
case default
12+
call abort()
13+
end select
14+
end program test_forall

0 commit comments

Comments
 (0)