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

Error on opening a file with match / case #19

Closed
aaannestad opened this issue Nov 28, 2023 · 2 comments
Closed

Error on opening a file with match / case #19

aaannestad opened this issue Nov 28, 2023 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@aaannestad
Copy link

aaannestad commented Nov 28, 2023

This version of semshi throws an error when trying to open a file involving Python 3.10's match/case syntax. (I've switched to this from the original numirias/semshi because that just treats a use of match as an error in your Python code!) It's possible this is my fault for switching from numirias/semshi incorrectly, but all other Python files seem to open just fine - it's only files using the match/case syntax that throw an error.

Steps to reproduce:

  • Save a file containing the following code:
def test(arg):
    match arg:
        case True:
            print('worked')
        case False:
            print('didnt work')

test(False)
  • Reopen the test file with neovim

You should get a large error like the following (probably not partially in Norwegian, but you get the idea):

Feil oppdaget under prosessering av BufReadPost Autokommandoer for "*":
Error executing lua callback: /usr/share/nvim/runtime/filetype.lua:24: Error executing lua: /usr/share/nvim/runtime/filetype.lua:25: BufReadPost Autokommandoer for "*"..FileType Autokommandoer for "*"..function <SNR>12_filetype_changed[4]..remote#define#CommandBootstrap[5]..remote#define#request, line 2: Vim(let):Error invoking '/home/[USER]/.local/share/nvim/plugged/semshi/rplugin/python3/semshi:command:Semshi' on channel 3 (pytho
n3-rplugin-host):Feil oppdaget under prosessering av BufReadPost Autokommandoer for "*":
Error executing lua callback: /usr/share/nvim/runtime/filetype.lua:24: Error executing lua: /usr/share/nvim/runtime/filetype.lua:25: BufReadPost Autokommandoer for "*"..FileType Autokommandoer for "*"..function <SNR>12_filetype_changed[4]..remote#define#CommandBootstrap[5]..remote#define#request, line 2: Vim(let):Error invoking '/home/[USER]/.local/share/nvim/plugged/semshi/rplugin/python3/semshi:command:Semshi' on channel 3 (pytho
n3-rplugin-host):
error caught in request handler '/home/[USER]/.local/share/nvim/plugged/semshi/rplugin/python3/semshi:command:Semshi [['enable']]':
Traceback (most recent call last):
  File "/home/[USER]/.local/share/nvim/plugged/semshi/rplugin/python3/semshi/plugin.py", line 151, in cmd_semshi
    func(self, *args[1:])
  File "/home/[USER]/.local/share/nvim/plugged/semshi/rplugin/python3/semshi/plugin.py", line 35, in wrapper
    func(self, *args, **kwargs)
  File "/home/[USER]/.local/share/nvim/plugged/semshi/rplugin/python3/semshi/plugin.py", line 174, in enable
    self.highlight()
  File "/home/[USER]/.local/share/nvim/plugged/semshi/rplugin/python3/semshi/plugin.py", line 35, in wrapper
    func(self, *args, **kwargs)
  File "/home/[USER]/.local/share/nvim/plugged/semshi/rplugin/python3/semshi/plugin.py", line 197, in highlight
    self._cur_handler.update(force=True, sync=True)
  File "/home/[USER]/.local/share/nvim/plugged/semshi/rplugin/python3/semshi/handler.py", line 71, in update
    self._update_step(force=force, sync=True)
  File "/home/[USER]/.local/share/nvim/plugged/semshi/rplugin/python3/semshi/util.py", line 19, in wrapper
    res = func(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^
  File "/home/[USER]/.local/share/nvim/plugged/semshi/rplugin/python3/semshi/handler.py", line 163, in _update_step
    add, rem = self._parser.parse(code, force)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/[USER]/.local/share/nvim/plugged/semshi/rplugin/python3/semshi/util.py", line 19, in wrapper
    res = func(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^
  File "/home/[USER]/.local/share/nvim/plugged/semshi/rplugin/python3/semshi/parser.py", line 47, in parse
    return self._parse(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/[USER]/.local/share/nvim/plugged/semshi/rplugin/python3/semshi/parser.py", line 68, in _parse
    new_nodes = self._make_nodes(code, new_lines, change_lineno)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/[USER]/.local/share/nvim/plugged/semshi/rplugin/python3/semshi/parser.py", line 108, in _make_nodes
    return visitor(lines, symtable_root, ast_root)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/[USER]/.local/share/nvim/plugged/semshi/rplugin/python3/semshi/util.py", line 19, in wrapper
    res = func(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^
  File "/home/[USER]/.local/share/nvim/plugged/semshi/rplugin/python3/semshi/visitor.py", line 50, in visitor
    visitor.visit(ast_root)
  File "/home/[USER]/.local/share/nvim/plugged/semshi/rplugin/python3/semshi/visitor.py", line 130, in visit
    self._iter_node(node)
  File "/home/[USER]/.local/share/nvim/plugged/semshi/rplugin/python3/semshi/visitor.py", line 413, in _iter_node
    self.visit(item)
  File "/home/[USER]/.local/share/nvim/plugged/semshi/rplugin/python3/semshi/visitor.py", line 120, in visit
    self._iter_node(node)
  File "/home/[USER]/.local/share/nvim/plugged/semshi/rplugin/python3/semshi/visitor.py", line 413, in _iter_node
    self.visit(item)
  File "/home/[USER]/.local/share/nvim/plugged/semshi/rplugin/python3/semshi/visitor.py", line 135, in visit
    self._iter_node(node)
  File "/home/[USER]/.local/share/nvim/plugged/semshi/rplugin/python3/semshi/visitor.py", line 413, in _iter_node
    self.visit(item)
  File "/home/[USER]/.local/share/nvim/plugged/semshi/rplugin/python3/semshi/visitor.py", line 135, in visit
    self._iter_node(node)
  File "/home/[USER]/.local/share/nvim/plugged/semshi/rplugin/python3/semshi/visitor.py", line 417, in _iter_node
    self.visit(value)
  File "/home/[USER]/.local/share/nvim/plugged/semshi/rplugin/python3/semshi/visitor.py", line 135, in visit
    self._iter_node(node)
  File "/home/[USER]/.local/share/nvim/plugged/semshi/rplugin/python3/semshi/visitor.py", line 417, in _iter_node
    self.visit(value)
  File "/home/[USER]/.local/share/nvim/plugged/semshi/rplugin/python3/semshi/visitor.py", line 135, in visit
    self._iter_node(node)
  File "/home/[USER]/.local/share/nvim/plugged/semshi/rplugin/python3/semshi/visitor.py", line 404, in _iter_node
    for field in node._fields:
                 ^^^^^^^^^^^^
AttributeError: 'bool' object has no attribute '_fields'
stack traceback:
        [C]: in function 'nvim_cmd'
        /usr/share/nvim/runtime/filetype.lua:25: in function </usr/share/nvim/runtime/filetype.lua:24>
        [C]: in function 'nvim_buf_call'
        /usr/share/nvim/runtime/filetype.lua:24: in function </usr/share/nvim/runtime/filetype.lua:10>
stack traceback:
        [C]: in function 'nvim_buf_call'
        /usr/share/nvim/runtime/filetype.lua:24: in function </usr/share/nvim/runtime/filetype.lua:10>
Trykk ENTER eller skriv kommando for å fortsette

You can bypass the error to continue editing the file, but the highlighting rules aren't fully operational.

If you replace the match/case syntax in the test code with an if/else statement, the file should open normally.

@wookayin
Copy link
Owner

I can confirm the bug, reproducible in both python3.10 and python3.11.

@wookayin wookayin added the bug Something isn't working label Nov 29, 2023
@wookayin wookayin added this to the 0.3.0 milestone Nov 29, 2023
@wookayin
Copy link
Owner

wookayin commented Nov 29, 2023

Fixed the error but I find it's not enough -- semantic highlight isn't quite correct. I will fix that too.

def test_match(arg, foo=False):
    match arg:
        case 42:
            print('constant')
        case foo:
        # case arg:
            print('arbitrary matching')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants