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] String taken from tuple compares inconsistently and prints incorrectly #2715

Open
ltjkoomen opened this issue May 17, 2024 · 0 comments
Labels
bug Something isn't working mojo-repo Tag all issues with this label

Comments

@ltjkoomen
Copy link

ltjkoomen commented May 17, 2024

Bug description

The string I got from a tuple compares inconsistently with values that should be exactly the same. Additionally, printing the string obtained from the tuple results in bogus characters.

See below for more details.

Steps to reproduce

Include relevant code snippet or link to code that did not work as expected.
I've come to the following minimal example:

alias T = SIMD[DType.int8, 1]


fn to_string(x: T) -> String:
    return String(x)


fn to_string_with_tuple(x: T) -> Tuple[String]:
    var y = to_string(x)
    print("y in function:", y)
    return (y,)


fn main():
    var v: T = 123
    print("v: ", v)
    var y = to_string(v)
    var out = to_string_with_tuple(v)
    var y_from_tuple = out.get[0, String]()

    if y_from_tuple != to_string(v):
        print("y_from_tuple NOT EQUAL TO to_string(v)")
    else:
        print("y_from_tuple EQUAL TO to_string(v)")
    if y_from_tuple != y:
        print("y_from_tuple NOT EQUAL TO y")
    else:
        print("y_from_tuple EQUAL TO y")

    print("y:", y)
    print("to_string(v):", to_string(v))
    print("y_from_tuple:", y_from_tuple)

Expectations:

  • I expect y_from_tuple, y, and String(v) to be equal in value
  • I expect the print function to print things with the same value in the same way

Results:

  • "y_from_tuple EQUAL TO to_string(v)" is printed, indicating they are equal. This is expected.
  • "y_from_tuple NOT EQUAL TO y" is printed, indicating they are not equal, this is unexpected since y is just to_string(v) stored in a variable.
  • "y: 123" and "to_string(v): 123" are printed as expected, but the final print statement prints bogus characters ("�" etc.) on my system. So even though y_from_tuple is equal in value to to_string(v) according to the if-statement, they print in a different way, the latter being printed correctly

If applicable, add screenshots to help explain the problem.
Not applicable.

If using the Playground, name the pre-existing notebook that failed and the steps that led to failure.
Not applicable.

Include anything else that might help us debug the issue.
Not applicable.

System information

- What OS did you do install Mojo on ?
Linux 6.5.0-35-generic #35~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May 7 09:00:52 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
- Provide version information for Mojo by pasting the output of `mojo -v`
mojo 24.3.0 (9882e19d)
- Provide Modular CLI version by pasting the output of `modular -v`
modular 0.8.0 (39a426b5)
@ltjkoomen ltjkoomen added bug Something isn't working mojo-repo Tag all issues with this label labels May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

1 participant