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

fix: Python bare return functions #171

Merged
merged 1 commit into from May 13, 2024
Merged

fix: Python bare return functions #171

merged 1 commit into from May 13, 2024

Conversation

amenrio
Copy link
Contributor

@amenrio amenrio commented Apr 22, 2024

Error:

Functions with only bare returns evaluate first, in line 62, the value nodes[i.Return] is set to nil, and because validate_direct_returns is evaluated after, it breaks on line 80, expecting a table but getting a nil value

Example code

def foo(bar=None):
    if not bar:
        return
    else:
        print(bar)

Throws this error:

E5108: Error executing lua ...dez/personal/neogen/lua/neogen/configurations/python.lua:80: bad argument #1 to 'pairs' (table expected, got nil)                                                                    
stack traceback:                                                                                                                                                                                                   
        [C]: in function 'pairs'                                                                                                                                                                                   
        ...dez/personal/neogen/lua/neogen/configurations/python.lua:80: in function 'validate_direct_returns'                                                                                                      
        ...dez/personal/neogen/lua/neogen/configurations/python.lua:251: in function 'extract'                                                                                                                     
        .../andres.mendez/personal/neogen/lua/neogen/granulator.lua:34: in function 'granulator'                                                                                                                   
        ...e/andres.mendez/personal/neogen/lua/neogen/generator.lua:280: in function 'generate'                                                                                                                    
        [string ":lua"]:1: in main chunk

Fix:

Swap execution order of validate_bare_returns and validate_direct_returns.

@amenrio amenrio changed the title fix: functions with only bare returns now evaluate properly fix: Python functions with only bare returns overrides value to be evaluated in validate_direct_returns Apr 22, 2024
@amenrio amenrio changed the title fix: Python functions with only bare returns overrides value to be evaluated in validate_direct_returns fix: Python functions with only bare returns override values to be evaluated in validate_direct_returns causing an error Apr 22, 2024
@amenrio amenrio changed the title fix: Python functions with only bare returns override values to be evaluated in validate_direct_returns causing an error fix: Python bare return functions Apr 22, 2024
@danymat danymat merged commit 6de0add into danymat:main May 13, 2024
1 check passed
@danymat
Copy link
Owner

danymat commented May 13, 2024

Hello, just merged :)
Sorry for the delay

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

Successfully merging this pull request may close these issues.

None yet

2 participants