hansec / fortran-language-server

Fortran Language Server for the Language Server Protocol
MIT License
294 stars 57 forks source link

False positive: Object not found in scope in case of "USE, NON_INTRINSIC" #206

Closed zaikunzhang closed 2 years ago

zaikunzhang commented 2 years ago

First of all, thank you for this great work!

With fortls 1.12.0, I get a false positive about "Object not found in scope". Here is a minimal working example.

!  testls.f90
module kind_mod
implicit none
private
public :: DP
integer, parameter :: DP = kind(0.0D0)
end module kind_mod

program testls
use, non_intrinsic :: kind_mod, only : DP
! If the last line is changed to `use kind_mod, only : DP`, then there is no problem.
implicit none
real(DP) :: x  ! fortls complains that `Object "dp" not found in scope`
x = 0.0_DP
end program testls

fortls complains that Object "dp" not found in scope in the program testls. The complaint will disappear if we replace

use, non_intrinsic :: kind_mod, only : DP

with

use kind_mod, only : DP

Thank you for your attention.

gnikit commented 2 years ago

You are indeed onto something, it would appear that the regex handling use statements only contains INTRINSIC. see: https://github.com/hansec/fortran-language-server/blob/e8479e89cf36c7fea5fed94cf5cb2de6c867ff51/fortls/parse_fortran.py#L17 I suspect that this might be a bigger pain than simply doing INTRINSIC|NON_INTRINSIC and read_use_stmt might need a small edit as well.

zaikunzhang commented 2 years ago

I suspect that this might be a bigger pain than simply doing INTRINSIC|NON_INTRINSIC and read_use_stmt might need a small edit as well.

Thank you, @gnikit , for the response!

I edited only USE_REGEX as you mentioned, but the problem persists. What edition would be needed for read_use_stmt? Sorry that I do not code Python, so I could not figure it out myself.

Thanks and regards, Zaikun

gnikit commented 2 years ago

The fix for this should be (INTRINSIC|NON_INTRINSIC) that is all. I will be pushing a patch in my fork

gnikit commented 2 years ago

@zaikunzhang FYI this has been in fortls since v1.14.3 (currently fortls is in v2.0.1)

zaikunzhang commented 2 years ago

Hello @gnikit ! Thank you very much for fixing this issue! Sorry that I missed your previous comment in December. I will try the new version.