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

VM rejects tuples containing uint64 with high bit set #11084

Closed
jrfondren opened this issue Apr 22, 2019 · 4 comments
Closed

VM rejects tuples containing uint64 with high bit set #11084

jrfondren opened this issue Apr 22, 2019 · 4 comments
Assignees
Labels
unsigned VM see also `const` label

Comments

@jrfondren
Copy link
Contributor

Compilation fails when tuples containing high-bit uint64 are assigned to consts. This is the case with literals and also with calculation (which is how I ran into it). It's not true of smaller integer sizes.

Example

var ok1: (uint64, array[1 .. 2, int]) = block:
  var b: array[1 .. 2, int]
  (0x8000_0000_0000_0000'u64, b)
var ok2: (seq[uint64], uint64) = block:
  var x: seq[uint64]
  x.add 0x8000_0000_0000_0000'u64
  (x, 0'u64)
var ok3: (char, uint64) = block:
  ('.', 1'u64 + 0x7FFF_FFFF_FFFF_FFFF'u64)
const ok4: array[1, uint64] = block:
  var b: array[1, uint64]
  b[0] = 1'u64 + 0x7FFF_FFFF_FFFF_FFFF'u64
  b
const ok5: seq[uint64] = block:
  @[0x8000_0000_0000_0000'u64]

when defined(arrbug):
  const bad1: (uint64, array[1 .. 2, int]) = block:
    var b: array[1 .. 2, int]
    (0x8000_0000_0000_0000'u64, b)

when defined(seqbug):
  const bad2: (seq[uint64], uint64) = block:
    var x: seq[uint64]
    x.add 0x8000_0000_0000_0000'u64
    (x, 0'u64)

when defined(charbug):
  const bad3: (char, uint64) = block:
    ('.', 1'u64 + 0x7FFF_FFFF_FFFF_FFFF'u64)

Example Output

# bin/nim c -d:charbug what.nim
Hint: used config file '/Users/jfondren/nim/Nim/config/nim.cfg' [Conf]
Hint: used config file '/Users/jfondren/nim/Nim/config/config.nims' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: what [Processing]
what.nim(30, 5) Error: cannot convert -9223372036854775808 to uint64

Additional Information

Observed in latest devel and in 0.19.4

@Clyybber
Copy link
Contributor

Clyybber commented Apr 22, 2019

I guess thats because the VM internally stores all integer types as int64.

@mratsim mratsim added unsigned VM see also `const` label labels Apr 22, 2019
@krux02 krux02 self-assigned this Oct 22, 2019
@narimiran
Copy link
Member

I've run all three cases (arrbug, seqbug and charbug) with the latest Nim and none of them produced the error provided above.

@jrfondren can you confirm that this now works?

@jrfondren
Copy link
Contributor Author

@narimiran with Nim 1.0.4 I still get all three bugs. I don't have any code that needs the bug to be fixed, so I could only confirm by running these same tests. If it's fixed in devel I'd say this issue is good to close.

@narimiran
Copy link
Member

If it's fixed in devel I'd say this issue is good to close.

I just confirmed that I can reproduce the problems on v1.0.x branch, and it is indeed fixed in devel. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unsigned VM see also `const` label
Projects
None yet
Development

No branches or pull requests

5 participants