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

fatal.nim(48) sysFatal Error: unhandled exception: value out of range: 4294967295 [RangeError] #11895

Open
citrusn opened this issue Aug 6, 2019 · 12 comments

Comments

@citrusn
Copy link

citrusn commented Aug 6, 2019

Nim Compiler Version 0.20.99 [Windows: i386]
Compiled at 2019-08-06

test.nim:

{.push checks:off.}
type
    REQUEST_RQ_TYPE* {.size: sizeof(uint32).} = enum    
      RRT_FORCE_DWORD =  -1, #0xFFFFFFFF
      RRT_GET = 1, 
      RRT_POST = 2, 
      RRT_PUT = 3, 
      RRT_DELETE = 4,
      RRT= 4294967295     
echo cast[uint](RRT_FORCE_DWORD)
{.pop.}

Error output:

fatal.nim(48)            sysFatal
Error: unhandled exception: value out of range: 4294967295 [RangeError]
@citrusn
Copy link
Author

citrusn commented Aug 6, 2019

This version is working correctly:
Nim Compiler Version 0.19.6 [Windows: i386]
Compiled at 2019-05-10

@krux02
Copy link
Contributor

krux02 commented Aug 6, 2019

There is an issue template that is supposed to guide you on how to properly report an issue. It has an example on how to write code examples and how to format the output. Please use it.

@mratsim mratsim added the Pragmas label Aug 7, 2019
@mratsim
Copy link
Collaborator

mratsim commented Aug 7, 2019

Cannot reproduce on my machine with devel from yesterday, as of commit 61c66ab

Also note that cast[uint](RRT_FORCE_DWORD) should not be allowed because uint and the enum size (uint32) differs (i.e. use uint(RRT_FORCE_DWORD) instead).

@citrusn
Copy link
Author

citrusn commented Aug 7, 2019

Build from github source :

Hint: used config file 'D:\Spc\nim-lastest\config\nim.cfg' [Conf]
Hint: used config file 'D:\Spc\nim-lastest\config\config.nims' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: test [Processing]
fatal.nim(48)            sysFatal
Error: unhandled exception: value out of range: 4294967295 [RangeError]

D:\Spc\nim-lastest\bin>nim.exe -v
Nim Compiler Version 0.20.99 [Windows: i386]
Compiled at 2019-08-07
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: 8407a574992ebd6bccec647a902cf54a4de8db18
active boot switches: -d:release

My machine is 32 bit and has sizeof(uint)=sizeof(uint32)=4

@krux02
Copy link
Contributor

krux02 commented Aug 7, 2019

this test should be reevaluated after this PR has been merged: #11701

@citrusn
Copy link
Author

citrusn commented Aug 7, 2019

This test was performed now from the current devel branch. Maybe I'm doing something wrong..

@krux02
Copy link
Contributor

krux02 commented Aug 7, 2019

No, you did everything right. The link is a branch I recently worked on (not yet merged into devel). There I worked a lot on the range checks that are implemented in the compiler. I can't guarantee that this BUG is fixed there, but it is possible.

@krux02
Copy link
Contributor

krux02 commented Aug 7, 2019

@citrusn can you try again? My PR got merged. For my machine your example works now as expected.

@citrusn
Copy link
Author

citrusn commented Aug 8, 2019

D:\Spc\nim-lastest2>git clone https://github.com/nim-lang/Nim nim-lastest2
oldnim.exe c Koch.nim
koch.exe boot

This code is good:

type
  REQUEST_RQ_TYPE* {.size: sizeof(uint32).} = enum
    RRT_FORCE_DWORD = -1, #0xFFFFFFFF
    RRT_GET = 1,
    RRT_POST = 2,
    RRT_PUT = 3,
    RRT_DELETE = 4#,
    #RRT= 4294967295
    #RRT = 0xFFFFFFFF
echo cast[uint32](RRT_FORCE_DWORD)

Output:

D:\Spc\nim-lastest2\bin>nim.exe c --run test.nim
Hint: used config file 'D:\Spc\nim-lastest2\config\nim.cfg' [Conf]
Hint: used config file 'D:\Spc\nim-lastest2\config\config.nims' [Conf]
Hint: operation successful (7563 lines compiled; 0.920 sec total; 11.766MiB peakmem; Debug Build) [SuccessX]
Hint: D:\Spc\nim-lastest2\bin\test.exe  [Exec]
4294967295

but, this don't works:

type
  REQUEST_RQ_TYPE* {.size: sizeof(uint32).} = enum
    #RRT_FORCE_DWORD = -1, #0xFFFFFFFF
    RRT_GET = 1,
    RRT_POST = 2,
    RRT_PUT = 3,
    RRT_DELETE = 4,
    #RRT= 4294967295
    RRT = 0xFFFFFFFF

echo cast[uint32](RRT_FORCE_DWORD) #, ' ',  RRT_FORCE_DWORD.uint32
D:\Spc\nim-lastest2\compiler\nim.nim(106) nim
D:\Spc\nim-lastest2\compiler\nim.nim(83) handleCmdLine
D:\Spc\nim-lastest2\compiler\cmdlinehelper.nim(92) loadConfigsAndRunMainCommand
D:\Spc\nim-lastest2\compiler\main.nim(198) mainCommand
D:\Spc\nim-lastest2\compiler\main.nim(94) commandCompileToC
D:\Spc\nim-lastest2\compiler\modules.nim(147) compileProject
D:\Spc\nim-lastest2\compiler\modules.nim(88) compileModule
D:\Spc\nim-lastest2\compiler\passes.nim(208) processModule
D:\Spc\nim-lastest2\compiler\passes.nim(86) processTopLevelStmt
D:\Spc\nim-lastest2\compiler\sem.nim(597) myProcess
D:\Spc\nim-lastest2\compiler\sem.nim(565) semStmtAndGenerateGenerics
D:\Spc\nim-lastest2\compiler\semstmts.nim(2185) semStmt
D:\Spc\nim-lastest2\compiler\semexprs.nim(984) semExprNoType
D:\Spc\nim-lastest2\compiler\semexprs.nim(2717) semExpr
D:\Spc\nim-lastest2\compiler\semstmts.nim(2125) semStmtList
D:\Spc\nim-lastest2\compiler\semexprs.nim(2722) semExpr
D:\Spc\nim-lastest2\compiler\semstmts.nim(1339) semTypeSection
D:\Spc\nim-lastest2\compiler\semstmts.nim(1185) typeSectionRightSidePass
D:\Spc\nim-lastest2\compiler\semtypes.nim(1791) semTypeNode
D:\Spc\nim-lastest2\compiler\semtypes.nim(125) semEnum
D:\Spc\nim-lastest2\lib\system\fatal.nim(48) sysFatal
Error: unhandled exception: value out of range: 4294967295 [RangeError]

@citrusn
Copy link
Author

citrusn commented Aug 8, 2019

This code is also good:

type
  REQUEST_RQ_TYPE* {.size: sizeof(uint32).} = enum
    RRT_FORCE_DWORD = 0xFFFFFFFF'i32,
    RRT_GET = 1,
    RRT_POST = 2,
    RRT_PUT = 3,
    RRT_DELETE = 4
    #RRT_FORCE_DWORD = 0xFFFFFFFF'u32 # but not this

@mratsim
Copy link
Collaborator

mratsim commented Aug 8, 2019

What if you use

type
  REQUEST_RQ_TYPE* {.size: sizeof(uint32).} = enum
    RRT_GET = 1'u32,
    RRT_POST = 2,
    RRT_PUT = 3,
    RRT_DELETE = 4
    RRT_FORCE_DWORD = 0xFFFFFFFF'u32

My guess is that it's because Nim tracks the value with int by default and 0xFFFFFFFF is not a valid int. I also know that the range check for literals changed after 0.19.6 because I used to test that in one of my libraries, probably stint

@citrusn
Copy link
Author

citrusn commented Aug 9, 2019

This is a great idea, but it doesn't work right now.
This is a valid, unsigned integer of 32 bits, which can be implicitly cast to the int32. The presence of pragma does not change anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants