lpython icon indicating copy to clipboard operation
lpython copied to clipboard

Bug: All numeric types accept invalid string literals as arguments

Open kmr-srbh opened this issue 1 year ago • 0 comments

The problem

The numeric types i32, i64, f32 and f64 accept String Constants and return value which a str variable can store. What I do here is highly unlikely to be done in the real world, but still, it is not the expected behavior.

from lpython import i32, i64, f32, f64

integer32: str = i32("Hello, LPython!")
integer64: str = i64("Hello, LPython!")
float32: str = f32("Hello, LPython!")
float64: str = f64("Hello, LPython!")

print("integer32:", integer32)
print("integer64:", integer64)
print("float32:", float32)
print("float64:", float64)
(lp) saurabh-kumar@Awadh:~/Projects/System/lpython$ ./src/bin/lpython ./examples/example.py
integer32: Hello, LPython!
integer64: Hello, LPython!
float32: Hello, LPython!
float64: Hello, LPython!

The solution

The solution is not to disallow accepting string arguments, we need them as mentioned in #2554 . Instead, we need to handle invalid string literals like the above. Hexadecimal and numbers in other bases must be handled too.

kmr-srbh avatar Mar 14 '24 12:03 kmr-srbh