Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: All numeric types accept invalid string literals as arguments #2602

Open
kmr-srbh opened this issue Mar 14, 2024 · 0 comments
Open

Bug: All numeric types accept invalid string literals as arguments #2602

kmr-srbh opened this issue Mar 14, 2024 · 0 comments

Comments

@kmr-srbh
Copy link
Contributor

kmr-srbh commented Mar 14, 2024

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 kmr-srbh changed the title Bug: All numeric types accept and return string arguments Bug: All numeric types accpet invalid string literals as arguments Mar 14, 2024
@kmr-srbh kmr-srbh changed the title Bug: All numeric types accpet invalid string literals as arguments Bug: All numeric types accept invalid string literals as arguments Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant