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

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

Closed
dreamflow opened this issue Dec 27, 2023 · 1 comment · Fixed by #23930
Closed

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

dreamflow opened this issue Dec 27, 2023 · 1 comment · Fixed by #23930

Comments

@dreamflow
Copy link

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

@ringabout
Copy link
Member

ringabout commented Dec 27, 2023

Duplicate of #22085 #12700

@ringabout ringabout reopened this Aug 8, 2024
@Araq Araq closed this as completed in f0e1eef Aug 11, 2024
narimiran pushed a commit that referenced this issue Sep 13, 2024
fixes #14522
fixes #22085
fixes #12700
fixes #23132
closes #22343 (succeeded by this PR)
completes nim-lang/RFCs#175

follow up #12688

(cherry picked from commit f0e1eef)
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

Successfully merging a pull request may close this issue.

2 participants