lpython icon indicating copy to clipboard operation
lpython copied to clipboard

Misleading error message on `0x_BAD__BEEF`

Open rebcabin opened this issue 1 year ago • 5 comments

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

rebcabin avatar Jun 22 '23 18:06 rebcabin

I think we don't support _ in hexadecimal numbers, only in decimal integers.

certik avatar Jun 22 '23 19:06 certik

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: @.***>

rebcabin avatar Jun 22 '23 20:06 rebcabin

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.

akshaypatel774 avatar Mar 19 '24 20:03 akshaypatel774

Hello @akshaypatel774! The error above persists. You can test it by trying to compile:

print(0x_BAD__BEEF)

kmr-srbh avatar Mar 24 '24 05:03 kmr-srbh

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'?

NishantBansal2003 avatar Apr 04 '24 10:04 NishantBansal2003