Skip to content

Private variable declaration in module seen in other scopes #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
stefabat opened this issue Feb 2, 2021 · 6 comments
Closed

Private variable declaration in module seen in other scopes #191

stefabat opened this issue Feb 2, 2021 · 6 comments

Comments

@stefabat
Copy link

stefabat commented Feb 2, 2021

Hi

I am using the fortran language server (FLS) in vscode, so I am not sure if it is a problem of the extension I am using, or the FLS itself. I suspect the second.

I have a private variable declared in a module with the same name as an intrinsic fortran keyword:

module foo
  implicit none
  private
  integer len
end module foo

Somewhere else in the code, I declare

character(len=*) :: bar = 'bar'

And vscode (through the FLS) is marking it as an error and saying 'object "len" not found in scope' and points me to the module above.
Furthermore, if I start typing

use foo, only: l...

the auto completion suggests me the variable len even though this is private and should not be seen. Indeed, trying to use the variable len anywhere else in the code runs into a compilation error with gfortran.

Any idea on what is going on?

@gnikit
Copy link

gnikit commented Dec 20, 2021

So this is caused by fortls (sometimes?) not respecting the module scopes. I think there a few more issues that are caused from this, especially when it comes to autocompletion.

@gnikit
Copy link

gnikit commented Jan 19, 2022

The extend of this bug is generally related to visibility scopes and modules.
If a variable is not defined as private or public in the same line e.g. integer, private :: len then there seems to be an issue distinguishing the public from private scopes.

If I remember correctly all modules are public by default, so I think this should be relatively easy to fix.

gnikit referenced this issue in fortran-lang/fortls Jan 22, 2022
Closes Private variable declaration in module seen in other scopes #3
Closes Private variable declaration in module seen in other scopes #191
@gnikit
Copy link

gnikit commented Jan 22, 2022

@stefabat This has now been fixed in fortls v2.0.1

@stefabat
Copy link
Author

Thanks, but lately I haven't been able to have fortls working in my vscode at all... I am bit confused on what should be installed: pip install fortran-language-server or pip install fortls? Reagrdless of which, I actually install it in a conda environment and then point vscode to the fortls executable within the conda folder, but it doesn't work.

@gnikit
Copy link

gnikit commented Jan 22, 2022

I think that might be a mistake on my end in the pre release of Modern Fortran. If you have turned on an option for disabling fortls it will skip registering the server all together see fortran-lang/vscode-fortran-support#365 .
I'll fix it over the weekend and in another prerelease

@stefabat
Copy link
Author

stefabat commented Feb 2, 2022

Ok, I had time to fix my setup and everything works. I can confirm that this fixes the issue and I don't see anymore the error.

Just for completeness and future reference, this is the current setup with which I managed to have it working:
I don't want to mess up my distribution python packages with pip, so what I have is a miniconda installation that I activate with the modulefiles system (like in HPC clusters). With conda active, I created a new environment where I installed fortls with pip. Then, in VSCode I only use the Modern Fortran extension in the pre-release version (hence no FORTRAN Intellisense and vscode-modern-fortran-formatter) and I explicitly set the path to the fortls within the miniconda installation. Everything works!

@stefabat stefabat closed this as completed Feb 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants