Skip to content

Commit 6a82432

Browse files
authored
Merge pull request #280 from fortran-lang/gnikit/issue269
fix: associate block from Function result
2 parents eb6f618 + 59f4402 commit 6a82432

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
### Fixed
2828

29+
- Fixed bug where `associate` blocks for variables pointing to function results
30+
where not properly resolved
31+
([#269](https://github.com/fortran-lang/fortls/issues/269))
2932
- Fixed bug where the `langid` was not propagated correctly from the user
3033
settings to the LSP creation stage for all types of requests.
3134
([#257](https://github.com/fortran-lang/fortls/issues/257))

fortls/objects.py

+5
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,7 @@ def __init__(
11601160
args: str = "",
11611161
mod_flag: bool = False,
11621162
keywords: list = None,
1163+
keyword_info: dict = None,
11631164
result_type: str = None,
11641165
result_name: str = None,
11651166
):
@@ -1173,9 +1174,13 @@ def __init__(
11731174
self.result_name: str = result_name
11741175
self.result_type: str = result_type
11751176
self.result_obj: Variable = None
1177+
self.keyword_info: dict = keyword_info
11761178
# Set the implicit result() name to be the function name
11771179
if self.result_name is None:
11781180
self.result_name = self.name
1181+
# Used in Associated blocks
1182+
if self.keyword_info is None:
1183+
self.keyword_info = {}
11791184

11801185
def copy_interface(self, copy_source: Function):
11811186
# Call the parent class method

fortls/parse_fortran.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1493,14 +1493,15 @@ def parse(
14931493
log.debug("%s !!! SUBROUTINE - Ln:%d", line, line_no)
14941494

14951495
elif obj_type == "fun":
1496-
keywords, _ = map_keywords(obj_info.keywords)
1496+
keywords, keyword_info = map_keywords(obj_info.keywords)
14971497
new_fun = Function(
14981498
file_ast,
14991499
line_no,
15001500
obj_info.name,
15011501
args=obj_info.args,
15021502
mod_flag=obj_info.mod_flag,
15031503
keywords=keywords,
1504+
keyword_info=keyword_info,
15041505
result_type=obj_info.result.type,
15051506
result_name=obj_info.result.name,
15061507
)

test/test_server_hover.py

+14
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,20 @@ def test_hover_block():
366366
validate_hover(results, ref_results)
367367

368368

369+
def test_associate_block_func_result():
370+
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir / "hover")})
371+
file_path = test_dir / "hover" / "associate_block_2.f90"
372+
string += hover_req(file_path, 2, 14)
373+
string += hover_req(file_path, 3, 9)
374+
errorcode, results = run_request(string, fortls_args=["--sort_keywords", "-n", "1"])
375+
assert errorcode == 0
376+
ref_results = [
377+
"```fortran90\nLOGICAL FUNCTION :: hi\n```",
378+
"```fortran90\nLOGICAL FUNCTION :: hi\n```",
379+
]
380+
validate_hover(results, ref_results)
381+
382+
369383
def test_hover_submodule_procedure():
370384
"""Test that submodule procedures and functions with modifier keywords
371385
are correctly displayed when hovering.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
program associate_block_2
2+
implicit none
3+
associate (hi => say_hi())
4+
if (hi) print *, 'Bye'
5+
end associate
6+
contains
7+
logical function say_hi()
8+
say_hi = .true.
9+
end
10+
end program

0 commit comments

Comments
 (0)