lpython
lpython copied to clipboard
Misleading error message on `0x_BAD__BEEF`
CPython reports invalid hexadecimal literal
but LPython reports identifier
error. This hints at deeper problems in the LPython front end:
repro: expr43.py
0xBAD_BEEF
0x_BAD_BEEF
0x_BAD__BEEF
syntax error: Token '__BEEF' (of type 'identifier') is unexpected here
--> ./expr43.py:3:7
|
3 | 0x_BAD__BEEF
| ^^^^^^
Note: if any of the above error or warning messages are not clear or are lacking
context please report it to us (we consider that a bug that must be fixed).
(lp) ┌─(~/CLionProjects/lpython/lasr/LP-pycharm)─────────────────────────────────────────────────────────────────────────────────────────────────────────(brian@Golf37:s012)─┐
└─(11:44:37 on brian-lasr ✹ ✭)──> python 1 ↵ ──(Thu,Jun22)─┘
Python 3.10.2 | packaged by conda-forge | (main, Mar 8 2022, 15:52:47) [Clang 11.1.0 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 0x_BAD__BEEF
File "<stdin>", line 1
0x_BAD__BEEF
^
SyntaxError: invalid hexadecimal literal
I think we don't support _
in hexadecimal numbers, only in decimal integers.
my test show that you do, e.g. 0x_BAD_BEEF
is fine in both LPython and in
CPython. It's double underscore and trailing underscore that CPython
forbids as syntax error, and LPython forbids as an identifier error. I
think the error message is misleading.
On Thu, Jun 22, 2023 at 12:38 PM Ondřej Čertík @.***> wrote:
I think we don't support _ in hexadecimal numbers, only in decimal integers.
— Reply to this email directly, view it on GitHub https://github.com/lcompilers/lpython/issues/2005#issuecomment-1603212987, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABSRR2WSKL6INC2ZC7PR2LXMSNKPANCNFSM6AAAAAAZQTOPMQ . You are receiving this because you authored the thread.Message ID: @.***>
Hey certik! I cannot find expr43.py
mentioned above in tests directory. If it has been removed, I think we can close this issue or if it has been renamed please guide me, if it is possible.
Hello @akshaypatel774! The error above persists. You can test it by trying to compile:
print(0x_BAD__BEEF)
So what should we do -
should we change the error message in lpython to something like this?
syntax error: Token '__BEEF' is unexpected here (invalid hexadecimal literal)
Also, I can see that there are no tests(or maybe there are correct me if I am wrong) for type 'identifier'?