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

Prevent user from declaring variables and functions with same name #1992

Merged
merged 2 commits into from
Sep 24, 2022

Commits on Sep 23, 2022

  1. Prevent user from declaring variables and functions with same name

    * Today use can "declarae" a variable in NEURON block and
      then PROCEDURE or FUNCTION with the same name. For example,
      below doesn't raise any error today:
    
       ```python
       NEURON {
           SUFFIX glia
           RANGE alfa
       }
    
       FUNCTION alfa(v(mV)) {
           alfa = exp(v)
       }
       ```
    
    * The reason this works is that the `RANGE alfa` declaration in
      NEURON block id not complete (i.e. variable needs to be "defined"
      in block like ASSIGNED, PARAMETER etc) and hence doesn't appear
      anywhere in the generated code. If we try to use `alfa` as variable
      then that is warning and resulted into compilation error.
    
    * This behaviour kind of works but error prone. Apart from corner cases
      and confusing behaviour, it's difficult to do certain analysis that
      we would like to do (e.g. in new NMODL code generation).
    
    * So for the robustness and simplicity, we now throw an error if user
      try to declarte variable and function with the same name.
    
      ```console
       $ ./bin/nocmodl mod_x/test.mod
           Translating mod_x/test.mod into mod_x/test.cpp
           Error: alfa used as both variable and function in file mod/test.mod
      ```
    pramodk committed Sep 23, 2022
    Configuration menu
    Copy the full SHA
    7c4660b View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    f0fe629 View commit details
    Browse the repository at this point in the history