erg-lang / erg

A statically typed language compatible with Python
http://erg-lang.org
Apache License 2.0
2.69k stars 55 forks source link

Runtime error exit status becomes 0 #321

Closed toddlerer closed 1 year ago

toddlerer commented 1 year ago

Describe the bug?

Run-time error exit status in python is not reflected.

Reproducible code

$ erg -c "assert 1 == 2" ; echo $?         

Expected result

$ erg -c "assert 1 == 2" ; echo $?         
Traceback (most recent call last):
  File "<string>", line -1, in <module>
AssertionError
1

Because of the following

$ python -c "assert 1 == 2" ; echo $?
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AssertionError
1

Actual result

$ erg -c "assert 1 == 2" ; echo $?         
Traceback (most recent call last):
  File "<string>", line -1, in <module>
AssertionError
0

Additional context

OS: macOS 13 (Ventura)

Erg version

Erg 0.6.0

Python version

Python3.11.x

OS

Other (write in Additional context)

GreasySlug commented 1 year ago

It can be reproduced in windows10.

cargo rd -- -c "assert 1 == 2"; echo $LASTEXITCODE
[DEBUG] compiler\erg_compiler\compile.rs:0219: code object:
Disassembly of <code object <module> at 0xc4ac4fcb98, file "<string>", line 1>:
Name:              <module>
FileName:          <string>
Argument count:    0
Positional-only arguments: 0
Kw-only arguments: 0
Number of locals:  0
Stack size:        4
Flags:
Constants:
   0: Int(0)
   1: ["namedtuple"]
   2: ["path"]
   3: "\\?\C:\Users\user\.erg\lib\std"
   4: ["in_operator"]
   5: ["*"]
   6: Nat(1)
   7: Nat(2)
   8: None
Names:
   0: collections
   1: namedtuple
   2: ::#NamedTuple
   3: sys
   4: path
   5: ::#path
   6: append
   7: _erg_std_prelude
   8: in_operator
   9: ::#in_operator
   10: Nat
lnotab: []
1:
              0 RESUME
              2 LOAD_CONST                0 (Int(0))
              4 LOAD_CONST                1 (["namedtuple"])
              6 IMPORT_NAME               0 (collections)
              8 IMPORT_FROM               1 (namedtuple)
             10 STORE_GLOBAL              2 (::#NamedTuple)
             12 POP_TOP
             14 LOAD_CONST                0 (Int(0))
             16 LOAD_CONST                2 (["path"])
             18 IMPORT_NAME               3 (sys)
             20 IMPORT_FROM               4 (path)
             22 STORE_GLOBAL              5 (::#path)
             24 POP_TOP
             26 LOAD_NAME                 5 (::#path)
             28 LOAD_METHOD               6 (append)
             30 CACHE
             32 CACHE
             34 CACHE
             36 CACHE
             38 CACHE
             40 CACHE
             42 CACHE
             44 CACHE
             46 CACHE
             48 CACHE
             50 LOAD_CONST                3 ("\\?\C:\Users\user\.erg\lib\std")
             52 PRECALL                   1
             54 CACHE
             56 CALL                      1
             58 CACHE
             60 CACHE
             62 CACHE
             64 CACHE
             66 POP_TOP
             68 LOAD_CONST                0 (Int(0))
             70 LOAD_CONST                4 (["in_operator"])
             72 IMPORT_NAME               7 (_erg_std_prelude)
             74 IMPORT_FROM               8 (in_operator)
             76 STORE_GLOBAL              9 (::#in_operator)
             78 POP_TOP
             80 LOAD_CONST                0 (Int(0))
             82 LOAD_CONST                5 (["*"])
             84 IMPORT_NAME               7 (_erg_std_prelude)
             86 IMPORT_STAR
             88 PUSH_NULL
             90 LOAD_NAME                 10 (Nat)
             92 LOAD_CONST                6 (Nat(1))
             94 PRECALL                   1
             96 CACHE
             98 CALL                      1
            100 CACHE
            102 CACHE
            104 CACHE
            106 CACHE
            108 PUSH_NULL
            110 LOAD_NAME                 10 (Nat)
            112 LOAD_CONST                7 (Nat(2))
            114 PRECALL                   1
            116 CACHE
            118 CALL                      1
            120 CACHE
            122 CACHE
            124 CACHE
            126 CACHE
            128 COMPARE_OP                2 (==)
            130 CACHE
            132 CACHE
            134 POP_JUMP_FORWARD_IF_TRUE  2 (to 140)
            136 LOAD_ASSERTION_ERROR
            138 RAISE_VARARGS             1
            140 LOAD_CONST                8 (None)
            142 RETURN_VALUE              

[DEBUG] compiler\erg_compiler\compile.rs:0220: the compiling process has completed
Traceback (most recent call last):
  File "<string>", line -1, in <module>
AssertionError
0

Additional context

cargo rd
>>> assert 1 == 2
[DEBUG] compiler\erg_compiler\compile.rs:0233: code object:
Disassembly of <code object <module> at 0x2b191f8c58, file "<stdin>", line 1>:
Name:              <module>
FileName:          <stdin>
Argument count:    0
Positional-only arguments: 0
Kw-only arguments: 0
Number of locals:  0
Stack size:        4
Flags:
Constants:
   0: Int(0)
   1: ["namedtuple"]
   2: ["path"]
   3: "\\?\C:\Users\user\.erg\lib\std"
   4: ["in_operator"]
   5: ["*"]
   6: Nat(1)
   7: Nat(2)
   8: None
Names:
   0: collections
   1: namedtuple
   2: ::#NamedTuple
   3: sys
   4: path
   5: ::#path
   6: append
   7: _erg_std_prelude
   8: in_operator
   9: ::#in_operator
   10: Nat
lnotab: []
1:
              0 RESUME
              2 LOAD_CONST                0 (Int(0))
              4 LOAD_CONST                1 (["namedtuple"])
              6 IMPORT_NAME               0 (collections)
              8 IMPORT_FROM               1 (namedtuple)
             10 STORE_GLOBAL              2 (::#NamedTuple)
             12 POP_TOP
             14 LOAD_CONST                0 (Int(0))
             16 LOAD_CONST                2 (["path"])
             18 IMPORT_NAME               3 (sys)
             20 IMPORT_FROM               4 (path)
             22 STORE_GLOBAL              5 (::#path)
             24 POP_TOP
             26 LOAD_NAME                 5 (::#path)
             28 LOAD_METHOD               6 (append)
             30 CACHE
             32 CACHE
             34 CACHE
             36 CACHE
             38 CACHE
             40 CACHE
             42 CACHE
             44 CACHE
             46 CACHE
             48 CACHE
             50 LOAD_CONST                3 ("\\?\C:\Users\user\.erg\lib\std")
             52 PRECALL                   1
             54 CACHE
             56 CALL                      1
             58 CACHE
             60 CACHE
             62 CACHE
             64 CACHE
             66 POP_TOP
             68 LOAD_CONST                0 (Int(0))
             70 LOAD_CONST                4 (["in_operator"])
             72 IMPORT_NAME               7 (_erg_std_prelude)
             74 IMPORT_FROM               8 (in_operator)
             76 STORE_GLOBAL              9 (::#in_operator)
             78 POP_TOP
             80 LOAD_CONST                0 (Int(0))
             82 LOAD_CONST                5 (["*"])
             84 IMPORT_NAME               7 (_erg_std_prelude)
             86 IMPORT_STAR
             88 PUSH_NULL
             90 LOAD_NAME                 10 (Nat)
             92 LOAD_CONST                6 (Nat(1))
             94 PRECALL                   1
             96 CACHE
             98 CALL                      1
            100 CACHE
            102 CACHE
            104 CACHE
            106 CACHE
            108 PUSH_NULL
            110 LOAD_NAME                 10 (Nat)
            112 LOAD_CONST                7 (Nat(2))
            114 PRECALL                   1
            116 CACHE
            118 CALL                      1
            120 CACHE
            122 CACHE
            124 CACHE
            126 CACHE
            128 COMPARE_OP                2 (==)
            130 CACHE
            132 CACHE
            134 POP_JUMP_FORWARD_IF_TRUE  2 (to 140)
            136 LOAD_ASSERTION_ERROR
            138 RAISE_VARARGS             1
            140 LOAD_CONST                8 (None)
            142 PRINT_EXPR                
            144 LOAD_CONST                8 (None)
            146 RETURN_VALUE

[DEBUG] compiler\erg_compiler\compile.rs:0234: the compiling process has completed
Traceback (most recent call last):
  File "<string>", line 28, in <module>
  File "<string>", line 1, in <module>
  File "<stdin>", line -1, in <module>
AssertionError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 32, in <module>
NameError: name 'e' is not defined

>>>
[DEBUG] compiler\erg_compiler\compile.rs:0233: code object:
Disassembly of <code object <module> at 0x2b191f8c58, file "<stdin>", line 1>:
Name:              <module>
FileName:          <stdin>
Argument count:    0
Positional-only arguments: 0
Kw-only arguments: 0
Number of locals:  0
Stack size:        2
Flags:
Constants:
   0: None
lnotab: []
1:
              0 RESUME
              2 LOAD_CONST                0 (None)
              4 RETURN_VALUE

[DEBUG] compiler\erg_compiler\compile.rs:0234: the compiling process has completed
Write error: 確立された接続がホスト コンピューターのソウトウェアによって中止されました。 (os error 10053)