Skip to content

.uint8 : error at compile-time , no error at execution-time #23132

Closed
@dreamflow

Description

@dreamflow

Description

this runs fine

block :
    let test_u64 : uint64 = 0xFFFFFFFFFFFF03.uint64
    let test_u8  : uint8  = test_u64.uint8
    echo test_u8

and shows the value of the lowest byte : 3

but the same code at compile-time

static :
    let test_u64 : uint64 = 0xFFFFFFFFFFFF03.uint64
    let test_u8  : uint8  = test_u64.uint8
    echo test_u8

breaks with
Error: illegal conversion from '72057594037927683' to '[0..255]'
in the line

let test_u8  : uint8  = test_u64.uint8

Expected Output

to be the same as at execution-time :
3 , the value of the lowest byte

Possible Solution

in the nimvm implementation adding
before the conversion

and 0xFF

to extract the lowest byte and have it in range [0..255] ,
identical to the behaviour at execution-time .

Nim Version

nim -v

Nim Compiler Version 2.1.1 [Windows: amd64]
Compiled at 2023-12-26

Additional Information

compiled with the cmdLine
nim compile test.nim
on the gcc version :
winlibs-x86_64-posix-seh-gcc-13.2.0-mingw-w64ucrt-11.0.1-r3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions