Skip to content

Commit dece46a

Browse files
committed
fix(parser): trailing semicolons triggering end of scope diagnostics
Fixes #265
1 parent bf1a0bc commit dece46a

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242

4343
### Fixed
4444

45+
- Fixed end of scope errors raised by trailing semicolon in native parser
46+
([#265](https://github.com/fortran-lang/fortls/issues/265))
4547
- Fixed bug where parent scope for includes in AST could be `None`
4648
([#329](https://github.com/fortran-lang/fortls/issues/329))
4749
- Fixed preprocessor bug with `if` and `elif` conditionals

fortls/parsers/internal/parser.py

+1
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,7 @@ def parse(
13501350
multi_lines.extendleft(line_stripped.split(";"))
13511351
line = multi_lines.pop()
13521352
line_stripped = line
1353+
line_no_comment = line
13531354
# Test for scope end
13541355
if file_ast.end_scope_regex is not None:
13551356
match = FRegex.END_WORD.match(line_no_comment)

test/test_parser.py

+9
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,12 @@ def test_private_visibility_interfaces():
3939
err_str, _ = file.load_from_disk()
4040
file.parse()
4141
assert err_str is None
42+
43+
44+
def test_end_scopes_semicolon():
45+
file_path = test_dir / "parse" / "trailing_semicolon.f90"
46+
file = FortranFile(str(file_path))
47+
err_str, _ = file.load_from_disk()
48+
ast = file.parse()
49+
assert err_str is None
50+
assert not ast.end_errors
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
program trailing_semicolon_in_end_scope
2+
integer :: i
3+
do i=1, 3
4+
print *, "Hello World!"
5+
end do;
6+
end program trailing_semicolon_in_end_scope

0 commit comments

Comments
 (0)