Skip to content

LPython parses but CPython does not #1149

Open
@certik

Description

@certik

These are curious cases that LPython parses but CPython does not. These are artificial cases, but if we want to be 100% strict with regards to #1139, we should not allow it either, so that if things compile with LPython, they also work with CPython.

def f():
    i: i32
    a: i32 = 5; for i in range(10): print(i)

f()

Which gives:

$ lpython --show-ast a.py         
(Module [(FunctionDef f ([] [] [] [] [] [] []) [(AnnAssign (Name i Store) (Name i32 Load) () 1) (AnnAssign (Name a Store) (Name i32 Load) (ConstantInt 5 ()) 1) (For (Name i Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [(Expr (Call (Name print Load) [(Name i Load)] []))] [] ())] [] () ()) (Expr (Call (Name f Load) [] []))] [])
$ python  a.py            
  File "/Users/ondrej/repos/lpython/a.py", line 3
    a: i32 = 5; for i in range(10): print(i)
                ^^^
SyntaxError: invalid syntax

Metadata

Metadata

Assignees

No one assigned

    Labels

    ParserIssues or improvements related to parser

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions