Skip to content
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

Import statement in interface block causes uncontrolled error #187

Open
plevold opened this issue Dec 9, 2020 · 6 comments
Open

Import statement in interface block causes uncontrolled error #187

plevold opened this issue Dec 9, 2020 · 6 comments

Comments

@plevold
Copy link

plevold commented Dec 9, 2020

With this minimal example:

module class_myclass
    implicit none

    private
    public myclass

    type :: myclass
        private
    contains
        procedure(my_func), deferred :: my_func
    end type

    interface
        subroutine my_func(this)
            ! error happens when I start typing "myclass" here
            import myclass
        end subroutine
    end interface

end module

I get the following tracebacks in the VSCode output view when I start typing "myclass" after "import":

[Error - 08:15:27] Request textDocument/completion failed.
  Message: 'list' object has no attribute 'only_list'
  Code: -32603 
[object Object]
error handling request {'jsonrpc': '2.0', 'id': 84, 'method': 'textDocument/completion', 'params': {'textDocument': {'uri': 'file:///c%3A/Users/palle/dev/fortran-object-metamodel/fomm_iterator.f90'}, 'position': {'line': 16, 'character': 20}, 'context': {'triggerKind': 1}}}
Traceback (most recent call last):
  File "c:\python39\lib\site-packages\fortls\langserver.py", line 167, in handle
    resp = handler(request)
  File "c:\python39\lib\site-packages\fortls\langserver.py", line 551, in serve_autocomplete
    line_context, context_info = get_line_context(line_prefix)
  File "c:\python39\lib\site-packages\fortls\parse_fortran.py", line 144, in get_line_context
    if len(test_match[1].only_list) > 0:
AttributeError: 'list' object has no attribute 'only_list'
[Error - 08:15:28] Request textDocument/completion failed.
  Message: 'list' object has no attribute 'only_list'
  Code: -32603 
[object Object]
error handling request {'jsonrpc': '2.0', 'id': 86, 'method': 'textDocument/completion', 'params': {'textDocument': {'uri': 'file:///c%3A/Users/palle/dev/fortran-object-metamodel/fomm_iterator.f90'}, 'position': {'line': 16, 'character': 20}, 'context': {'triggerKind': 1}}}
Traceback (most recent call last):
  File "c:\python39\lib\site-packages\fortls\langserver.py", line 167, in handle
    resp = handler(request)
  File "c:\python39\lib\site-packages\fortls\langserver.py", line 551, in serve_autocomplete
    line_context, context_info = get_line_context(line_prefix)
  File "c:\python39\lib\site-packages\fortls\parse_fortran.py", line 144, in get_line_context
    if len(test_match[1].only_list) > 0:
AttributeError: 'list' object has no attribute 'only_list'
[Error - 08:15:29] Request textDocument/completion failed.
  Message: 'list' object has no attribute 'only_list'
  Code: -32603 
[object Object]
error handling request {'jsonrpc': '2.0', 'id': 87, 'method': 'textDocument/completion', 'params': {'textDocument': {'uri': 'file:///c%3A/Users/palle/dev/fortran-object-metamodel/fomm_iterator.f90'}, 'position': {'line': 16, 'character': 22}, 'context': {'triggerKind': 1}}}
Traceback (most recent call last):
  File "c:\python39\lib\site-packages\fortls\langserver.py", line 167, in handle
    resp = handler(request)
  File "c:\python39\lib\site-packages\fortls\langserver.py", line 551, in serve_autocomplete
    line_context, context_info = get_line_context(line_prefix)
  File "c:\python39\lib\site-packages\fortls\parse_fortran.py", line 144, in get_line_context
    if len(test_match[1].only_list) > 0:
AttributeError: 'list' object has no attribute 'only_list'
[Error - 08:17:48] Request textDocument/completion failed.
  Message: 'list' object has no attribute 'only_list'
  Code: -32603 
[object Object]
error handling request {'jsonrpc': '2.0', 'id': 170, 'method': 'textDocument/completion', 'params': {'textDocument': {'uri': 'file:///c%3A/Users/palle/dev/fortran-object-metamodel/myclass.f90'}, 'position': {'line': 14, 'character': 20}, 'context': {'triggerKind': 1}}}
Traceback (most recent call last):
  File "c:\python39\lib\site-packages\fortls\langserver.py", line 167, in handle
    resp = handler(request)
  File "c:\python39\lib\site-packages\fortls\langserver.py", line 551, in serve_autocomplete
    line_context, context_info = get_line_context(line_prefix)
  File "c:\python39\lib\site-packages\fortls\parse_fortran.py", line 144, in get_line_context
    if len(test_match[1].only_list) > 0:
AttributeError: 'list' object has no attribute 'only_list'
[Error - 08:17:56] Request textDocument/completion failed.
  Message: 'list' object has no attribute 'only_list'
  Code: -32603 
[object Object]
error handling request {'jsonrpc': '2.0', 'id': 172, 'method': 'textDocument/completion', 'params': {'textDocument': {'uri': 'file:///c%3A/Users/palle/dev/fortran-object-metamodel/myclass.f90'}, 'position': {'line': 14, 'character': 22}, 'context': {'triggerKind': 1}}}
Traceback (most recent call last):
  File "c:\python39\lib\site-packages\fortls\langserver.py", line 167, in handle
    resp = handler(request)
  File "c:\python39\lib\site-packages\fortls\langserver.py", line 551, in serve_autocomplete
    line_context, context_info = get_line_context(line_prefix)
  File "c:\python39\lib\site-packages\fortls\parse_fortran.py", line 144, in get_line_context
    if len(test_match[1].only_list) > 0:
AttributeError: 'list' object has no attribute 'only_list'
@gbogopolsky
Copy link

I notice the same on my side. Any idea about how to fix it?

@gnikit
Copy link

gnikit commented Dec 21, 2021

@plevold Is the rest of the syntax for this example legal? Can I ignore the diagnostic and linting errors in :: my_func and this?

@gnikit
Copy link

gnikit commented Dec 22, 2021

This has now been fixed in fortls v1.14.4 . The autocomplete suggestions are not "working" as expected i.e. the suggestions will not be limited to what was included with import. That will be fixed in a future release see: fortran-lang/fortls#8

@plevold
Copy link
Author

plevold commented Dec 22, 2021

@plevold Is the rest of the syntax for this example legal? Can I ignore the diagnostic and linting errors in :: my_func and this?

The original example was missing the declaration of the this argument. Also strictly speaking the type should have been abstract since it has a deferred procedure. Here's an example that gfortran compiles with no complaints using -Wall:

module class_myclass
    implicit none

    private
    public myclass

    type, abstract :: myclass
        private
    contains
        procedure(my_func), deferred :: my_func
    end type

    interface
        subroutine my_func(this)
            ! error happens when I start typing "myclass" here
            import myclass
            class(myclass), intent(in) :: this
        end subroutine
    end interface

end module

This has now been fixed in fortls v1.14.4 .

Awsome! Thanks a lot for the effort. This project is making Fortran development much more pleasant!

@gnikit
Copy link

gnikit commented Dec 22, 2021

@plevold Thanks for the example code. I will try and sort out the autocomplete suggestions in the next few weeks.

Glad to see people using the new fortls

@JHenneberg
Copy link
Contributor

@gnikit : You just need to be quite deep inside the fortran github bubble to find out about it. I updated my small guide (https://github.com/JHenneberg/Guide_VSCode-fortran) with your extension.

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

4 participants