Skip to content

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

Open
@kmr-srbh

Description

@kmr-srbh

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.

Activity

changed the title [-]Bug: All numeric types accept and return string arguments[/-] [+]Bug: All numeric types accpet invalid string literals as arguments[/+] on Mar 14, 2024
changed the title [-]Bug: All numeric types accpet invalid string literals as arguments[/-] [+]Bug: All numeric types accept invalid string literals as arguments[/+] on Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @kmr-srbh

        Issue actions

          Bug: All numeric types accept invalid string literals as arguments · Issue #2602 · lcompilers/lpython