Skip to content

Commit 6aaeedc

Browse files
committed
test(parser): add test for private interfaces
1 parent f42fc34 commit 6aaeedc

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

fortls/parsers/internal/parser.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from fortls.constants import (
1919
DO_TYPE_ID,
2020
INTERFACE_TYPE_ID,
21-
MODULE_TYPE_ID,
2221
SELECT_TYPE_ID,
2322
SUBMODULE_TYPE_ID,
2423
FRegex,
@@ -1657,10 +1656,10 @@ def parse(
16571656
msg = "Visibility statement without enclosing scope"
16581657
file_ast.add_error(msg, Severity.error, line_no, 0)
16591658
else:
1660-
if (len(obj_info.obj_names) == 0) and (obj_info.type == 1):
1659+
if len(obj_info.obj_names) == 0 and obj_info.type == 1: # private
16611660
file_ast.current_scope.set_default_vis(-1)
16621661
else:
1663-
if obj_info.type == MODULE_TYPE_ID:
1662+
if obj_info.type == 1: # private
16641663
for word in obj_info.obj_names:
16651664
file_ast.add_private(word)
16661665
else:

test/test_parser.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,11 @@ def test_submodule():
3131
except Exception as e:
3232
print(e)
3333
assert False
34+
35+
36+
def test_private_visibility_interfaces():
37+
file_path = test_dir / "vis" / "private.f90"
38+
file = FortranFile(str(file_path))
39+
err_str, _ = file.load_from_disk()
40+
file.parse()
41+
assert err_str is None

test/test_source/.fortls

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"./diag/",
1010
"docs",
1111
"rename",
12-
"parse"
12+
"parse",
13+
"vis"
1314
]
1415

1516
}

test/test_source/vis/private.f90

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module visibility
2+
private :: name
3+
private :: generic_interf
4+
interface name
5+
module procedure :: name_sp
6+
end interface name
7+
interface
8+
subroutine generic_interf(noop)
9+
integer, intent(in) :: noop
10+
end subroutine generic_interf
11+
end interface
12+
contains
13+
subroutine name_sp(val)
14+
real(4), intent(in) :: val
15+
print *, 'name_sp', val
16+
end subroutine name_sp
17+
end module visibility

0 commit comments

Comments
 (0)