-
-
Notifications
You must be signed in to change notification settings - Fork 804
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
None
in viper is misleading
#539
Comments
This is important to avoid subtle user errors from expecting Also has the side benefit of simplifying Formal Verification techniques |
+1 from my side to remove a |
+1 I don't see any point in having |
@fubuloubu @jacqueswww @yzhang90 For the initialization / removing of large arrays / mappings I see
As Viper is right now we'd have to empty |
But maybe a built-in like |
@fubuloubu How about struct? or other compound structures? I think
The remaining question is whether reset(map) is allowed. |
For a mapping, as per issue #570 it's not really clear what to do. I think A little bit of documentation around |
Should |
Initial values that are zeros, with no zeroing functions.
Remove None as a type. |
Well, for a struct, we can just say all values inside are assumed to be their corresponding zero values, Idea: for myStruct: {
a: int128,
b: bytes32
}
# Assignments
myStruct = { a: 2, b: 0b1000_0001 } # Sets both a and b
myStruct = { a: 2 } # b is assumed to be null, or 0b0
myStruct = { } # both a and b are assumed null (0 ad 0b0)
# Comparisions
assert myStruct == { a: 2, b: 0b1000_0001 } # Checks myStruct == { a: 2, b: 0b1000_0001 }
assert myStruct == { a: 2 } # checks myStruct == { a: 2, b: 0b0 }
assert myStruct == { } # checks myStruct == { a: 0, b: 0b0 } Might be a little bit magical, but I think it's interesting and it solves the problem of not using |
Starting a crack at this, will push a WIP later this evening. |
@jakerockland just check if this is still valid, I have faint memory of partially removing some parts of this. |
@jacqueswww could you elaborate a bit on what you mean by "this" when you say to check if this is still valid 😅? For context I just pushed my initial change to a WIP at #1106, I believe this appropriately catches assignment to |
That looks good. 👍 |
go right ahead, I think I was confused that this was already implemented. |
|
Yup! 😊 |
What's your issue about?
NullType
valueNone
in viper is misleading.For base type,
None
is converted to 0, which means:If a list is assigned
None
, the list will get initialized to zeroes.If a byte array is assigned
None
, it is equivalent to an empty string ( but compiled codes are different).These behaviors are quite misleading.
How can it be fixed?
Since the actual behavior is nothing more than giving a variable default value, I suggest removing the
None
keyword from the syntax.Cute Animal Picture
The text was updated successfully, but these errors were encountered: