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

Warnings when unpacking to an object with range properties #64

Open
termermc opened this issue Feb 11, 2022 · 1 comment
Open

Warnings when unpacking to an object with range properties #64

termermc opened this issue Feb 11, 2022 · 1 comment

Comments

@termermc
Copy link

Warnings (that will eventually turn into errors) are raised when unpacking to an object that has properties which are ranges.

Here is my object and the type definition for its property:

type
    StreamId* = uint32 ## A stream ID
    NonBlankStreamId* = range[((StreamId) 1)..high(StreamId)] ## A non-blank stream ID
    CSendStreamData* = object
        ## Sent to convert the connection into a stream data input pipe.
        
        streamId*: NonBlankStreamId ## The stream to send data to

Unpacking it with the following code:

body.unpack(CSendStreamData)

The compiler generates the following warning:

<home>/.nimble/pkgs/msgpack4nim-0.3.1/msgpack4nim.nim(1217, 9) Warning: Cannot prove that 'result' is initialized. This will become a compile time error in the future. [ProveInit]

While this doesn't stop the code from compiling (for now), it does show as an error in the VS Code extension and is annoying in that way. The main issue here is the implication that this code may not compile in later versions of Nim. I believe that if the data being unpacked violates the range, that it should raise a ObjectConversionDefect, since that would be consistent.

My nim -v output:

Nim Compiler Version 1.6.2 [Linux: amd64]
Compiled at 2021-12-17
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: 9084d9bc02bcd983b81a4c76a05f27b9ce2707dd
active boot switches: -d:release

Thanks! Other than this, your project has been working amazingly for me.

@jangko
Copy link
Owner

jangko commented Feb 24, 2023

reminder for me:
the solution for this is to add a macro that can traverse from parent object to every inner fields and then construct a range initialization code if one of the fields in the hierarchy contains fields with requires init attribute.
explicit {.requiresInit.} or implicit one like range should be taken into account.

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

2 participants