Skip to content

"distinct uint64" type corruption on 32-bit, when using {.borrow.} operators #13902

@stefantalpalaru

Description

@stefantalpalaru

The problem only appears when borrowed operators for a "distinct uint64" type force a type inference.

Example

type Slot = distinct uint64

var s = Slot(1)

proc `$`*(x: Slot): string {.borrow.}
proc `+=`*(x: var Slot, y: uint64) {.borrow.}

echo "s = ", s
s += 1
echo "s = ", s

Compiling and running a 32-bit binary on a 64-bit Linux system: nim c -r --cpu:i386 --passC:"-m32" --passL:-m32 uint64.nim

Current Output

s = 1
s = 6223254620873949186

Expected Output

s = 1
s = 2

Additional Information

Found when porting nim-beacon-chain to Nim-1.2.0: status-im/nimbus-eth2#829

$ nim -v
Nim Compiler Version 1.2.0 [Linux: amd64]
Compiled at 2020-04-03
Copyright (c) 2006-2020 by Andreas Rumpf

active boot switches: -d:release

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions