Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Script-level variables should go in global scope ? #1941

Open
@rebcabin

Description

@rebcabin

https://github.com/rebcabin/lpython/blob/29f113ace4f62810d57a58e290dcc422cbea6fcb/lasr/lpython/lasr_lexer_global_scope_Issue_1940.py

The following works in ordinary CPython:

def read_seek_tell_test():
    a_char: str = read(fd, 1)  ############ ATTENTION #############
    assert a_char == '('
    a_char = read(fd, 1)
    assert a_char == 'I'
    assert tell(fd) == 2
    assert seek(fd, 0, SEEK_SET) == 0
    assert seek(fd, 100, SEEK_SET) == 100
    assert seek(fd, 2, SEEK_SET) == 2
    temp: str = read(fd, -1)
    assert temp == 'nteger 4 [])'
    assert tell(fd) == 14


if __name__ == '__main__':
    integer_asr : str = '(Integer 4 [])'
    fd   : StringIO = StringIO(integer_asr, 0, 0)   ############ ATTENTION ##############
    __post_init__(fd)  # Issue #1929
    stringio_test()
    read_seek_tell_test()

because the variable fd goes into global scope.

LPython complains:

└─(14:11:15 on brian-lasr ✹ ✭)──> ~/CLionProjects/lpython/src/bin/lpython lasr_lexer.py && ./lasr_lexer.out                                               ──(Sun,Jun18)─┘
semantic error: 'fd' is not defined in the scope
  --> lasr_lexer.py:87:12
   |
87 |     assert fd._buf == integer_asr
   |            ^^^^^^^ 

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions