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

Format.int[A] always formats as U64, even when A is U128 or I128 #2015

Closed
nisanharamati opened this issue Jul 7, 2017 · 3 comments
Closed

Comments

@nisanharamati
Copy link
Contributor

When using Format.int[U128] or Format.int[I128], it always ends up running the logic from _FormatInt.u64.

This is happening because of the identity conditionals in Format.int[A] return false, as x is never identical to an uninstantiated primitive.

    if x is U128 then
      _FormatIntt.u128(x.u128(), false, fmt, prefix, prec, width, align, fill)
    elseif x is I128 then
      _FormatIntt.u128(abs.u128(), neg, fmt, prefix, prec, width, align, fill)
    else
      _FormatIntt.u64(abs.u64(), neg, fmt, prefix, prec, width, align, fill)
    end

To reproduce:

use "format"

actor Main
  new create(env: Env) =>
    let u128_max: U128 = U128.max_value()
    let s128_max = Format.int[U128](where x=u128_max, fmt=FormatHexBare)
    let s128_max': String val = consume s128_max
    env.out.print("Expected: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")
    env.out.print("Got: " + s128_max')
    try
      let u128_decoded = s128_max'.u128(16)
      env.out.print("Original: " + u128_max.string())
      env.out.print("Formtted + parserd: " + u128_decoded.string())
    end
@Praetonus
Copy link
Member

This will be fixed in the 0.15 release, which should happen soon. The fix was done in #1927.

@nisanharamati
Copy link
Contributor Author

Ah! Sorry for the duplicate! I must have missed it when I was searching for existing issues related to this.

@Praetonus
Copy link
Member

No worries, it's better to have a bug reported twice than never.

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

2 participants