Skip to content

Commit

Permalink
[ysh translation] Fix int literal bug by removing 0b 0o 0x prefixes
Browse files Browse the repository at this point in the history
Python allows int('0b10', 2), but we don't.
  • Loading branch information
Andy Chu committed Jan 30, 2024
1 parent 41ac36c commit cf43b50
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 1 addition & 2 deletions spec/ysh-command-sub.test.sh
@@ -1,7 +1,6 @@
## oils_failures_allowed: 1


#### conflict with extglob @( cna be avoided with ,(
#### Conflict with extglob @( can be avoided with ,(

shopt -s extglob

Expand Down
9 changes: 6 additions & 3 deletions ysh/expr_eval.py
Expand Up @@ -392,11 +392,14 @@ def _EvalConst(self, node):
if id_ == Id.Expr_DecInt:
return value.Int(int(c_under))
if id_ == Id.Expr_BinInt:
return value.Int(int(c_under, 2))
assert c_under[:2] in ('0b', '0B'), c_under
return value.Int(int(c_under[2:], 2))
if id_ == Id.Expr_OctInt:
return value.Int(int(c_under, 8))
assert c_under[:2] in ('0o', '0O'), c_under
return value.Int(int(c_under[2:], 8))
if id_ == Id.Expr_HexInt:
return value.Int(int(c_under, 16))
assert c_under[:2] in ('0x', '0X'), c_under
return value.Int(int(c_under[2:], 16))

if id_ == Id.Expr_Float:
# Note: float() in mycpp/gc_builtins.py currently uses strtod
Expand Down

0 comments on commit cf43b50

Please sign in to comment.