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

Const variables not recognised as variable definition #367

Open
ghost opened this issue Aug 16, 2020 · 0 comments
Open

Const variables not recognised as variable definition #367

ghost opened this issue Aug 16, 2020 · 0 comments

Comments

@ghost
Copy link

ghost commented Aug 16, 2020

If a script-local variable is defined with const, it is not recognized as a variable definition, e.g. a file test.vim with the content

const s:aa = 1
echomsg s:aa

yields as output of vint -w test.vim

test.vim:1:7: Undefined variable: s:aa (see :help E738)
test.vim:2:9: Undefined variable: s:aa (see :help E738)

Replacing const with let lets the warning go away. Likewise using aa instead of s:aa as variable name solves it, too.

My guess is that const x = y is not recognised as a definition.
I have no clue how vint works but if I add the following the warning vanishes:

--- a/vint/ast/plugin/scope_plugin/identifier_classifier.py
+++ b/vint/ast/plugin/scope_plugin/identifier_classifier.py
@@ -26,6 +26,7 @@ DECLARING_IDENTIFIERS = 'VINT:declaring_identifiers'
 
 DeclarativeNodeTypes = {
     NodeType.LET: True,
+    NodeType.CONST: True,
     NodeType.FUNCTION: True,
     NodeType.FOR: True,
     NodeType.EXCMD: True,
@@ -463,6 +464,18 @@ class IdentifierClassifier(object):
         )
 
 
+    def _enter_const_node(self, const_node, is_on_lambda_body, is_on_lambda_str):
+        # Only "=" operator can be used as declaration.
+        if const_node['op'] != '=':
+            return
+
+        self._enter_assignment_node(
+            const_node,
+            is_on_lambda_str=is_on_lambda_str,
+            is_on_lambda_body=is_on_lambda_body,
+        )
+
+
     def _enter_for_node(self, for_node, is_on_lambda_body, is_on_lambda_str):
         self._enter_assignment_node(
             for_node,
@@ -526,6 +539,13 @@ class IdentifierClassifier(object):
                 is_on_lambda_body=is_on_lambda_body,
             )
 
+        elif node_type is NodeType.CONST:
+            self._enter_const_node(
+                node,
+                is_on_lambda_str=is_on_lambda_str,
+                is_on_lambda_body=is_on_lambda_body,
+            )
+
         elif node_type is NodeType.FOR:
             self._enter_for_node(
                 node,

Remark: _enter_const_node() is exactly the same as _enter_let_node()
(except a variable name).

Note: There is also a DeclarativeNodeTypes in vint/ast/plugin/scope_plugin/scope_linker.py but that seems unused. So maybe that should be removed.

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

0 participants