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

Use u64 in string format specifier #2059

Open
mzagozen opened this issue Jan 8, 2025 · 2 comments
Open

Use u64 in string format specifier #2059

mzagozen opened this issue Jan 8, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@mzagozen
Copy link
Collaborator

mzagozen commented Jan 8, 2025

Acton Version

0.24.1.20250108.8.28.39

Steps to Reproduce and Observed Behavior

I would like to use an u64 (and other smaller types like u32, ...) value if a string format specifier with %d:

def _test_format_unboxed():
    p = u64(4)
    s = "p = %d" % p

The compiler wants a

ERROR: Error when compiling tf2 module: Type error

   |
15 |    s = "p = %d" % p
   |                   ^
The type of the indicated expression (inferred to be __builtin__.u64) must be a subclass of __builtin__.int

Expected Behavior

Have the code work without the need to convert to int with int(p).

@mzagozen mzagozen added the bug Something isn't working label Jan 8, 2025
@nordlander
Copy link
Contributor

Ah, this is one of the unfortunate effects of not having integer subtyping in place! We could possibly try fix it via overloading of print, but integer subtyping is something we're planning to support soon anyway. So I propose we defer the issue until then.

@plajjan
Copy link
Contributor

plajjan commented Jan 8, 2025

Workarounds:

  • print("hello:", u64(123))
  • print("hello: %d" % int(u64(123)))
  • print("hello: %s" % str(u64(123)))
  • print("hello: " + str(u64(123)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants