Summary
This issue is about runtime 'string-to-int' path in builtin.codon, int._from_str.
Not the earlier parser-level integer literal issue from #783 .
Two problems were found in stdlib/internal/builtin.codon:
- short prefixed (especially, with length 3) strings such as
0x0, 0b1, or 0o6 fail
- numeric strings containing underscores such as
1_101 or 0b1_101 fail
Problem 1: short prefixed strings
Inputs like below should work:
int("0b0", 0)
int("0x1", 0)
int("0o6", 0)
But Instead, they shows below error.
ValueError: invalid literal for int() with base 0: '0b0'
Raised from: int._from_str:0.parse_error.0:0
/home/swchoi/src/codon/install/lib/codon/stdlib/internal/builtin.codon:380:13
Aborted (core dumped)
Problem 2: underscores in numeric strings
Inputs like below should work:
print("w08 python gap string underscores binary")
print(int("1_101", 2))
print(int("0b1_101", 0))
And they shows
w08 python gap string underscores binary
ValueError: invalid literal for int() with base 2: '1_101'
Raised from: int._from_str:0.parse_error.0:0
/home/swchoi/src/codon/install/lib/codon/stdlib/internal/builtin.codon:380:13
Backtrace:
[0x75cd18ad1738] int._from_str:0.parse_error.0:0[str,int].1342 at /home/swchoi/src/codon/install/lib/codon/stdlib/internal/builtin.codon:380:13
[0x75cd18ad24d3] int._from_str:0[str,int].1390 at /home/swchoi/src/codon/install/lib/codon/stdlib/internal/builtin.codon:457:29
[0x75cd18ad250f] int.__new__:1[str,int].1393 at /home/swchoi/src/codon/install/lib/codon/stdlib/internal/types/int.codon:14:33
[0x75cd18ad5090] main.0 at /home/swchoi/src/test_code/codon_counter_exp/w08_python_gap_string_underscores_binary.codon:2:20
Aborted (core dumped)
This issue is seperate from #783 I think.
Since this issue is not octal-only, and affects every prefixed numeric strings.
Summary
This issue is about runtime 'string-to-int' path in
builtin.codon,int._from_str.Not the earlier parser-level integer literal issue from #783 .
Two problems were found in
stdlib/internal/builtin.codon:0x0,0b1, or0o6fail1_101or0b1_101failProblem 1: short prefixed strings
Inputs like below should work:
But Instead, they shows below error.
Problem 2: underscores in numeric strings
Inputs like below should work:
And they shows
This issue is seperate from #783 I think.
Since this issue is not octal-only, and affects every prefixed numeric strings.