-
Notifications
You must be signed in to change notification settings - Fork 187
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
require initialization of structs and arrays at decl site #747
Conversation
532cc32
to
6252820
Compare
b909d29
to
363b32b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some inline comments. Most important: Can you confirm we don't need that for tuple types? Wouldn't something like let val: (u8, u8, address)
run into the same issue?
@@ -264,7 +264,7 @@ note: | |||
┌─ aug_assign.fe:65:5 | |||
│ | |||
65 │ ╭ pub fn add_from_mem(a: u256, b: u256) -> u256 { | |||
66 │ │ let my_array: Array<u256, 10> | |||
66 │ │ let my_array: Array<u256, 10> = [0; 10] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding this repeat expression feels a bit like a crutch to me. It doesn't seem overly useful for the user since it only allows a single value to be repeated. Did you consider to just initialize the array with default values on behalf of the user. Maybe that gets complicated if the array is over a complex type such as Array<Customer, 10>
. However, in the future we could have a Default
trait and if a user wants to initialize an array of Array<Customer, 10>
then it will automatically use the values provided by Customer::default()
or else error if Customer
doesn't implement the Default
trait. I'm just thinking out loud here...I'm not really against introducing the repeat expression but if in the future we find a way to get rid of it again or make it more useful I wouldn't be sad to see it go 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I just learned that one can use the same approach to initialize fixed size arrays in Rust. So, I guess it's fine. I still think that in the future it could be nice syntactical sugar if one could just write let x: Array<Customer, 10>
and it would de-sugar into something like let x: Array<Customer, 10> = [Customer::default(), 10]
. And if T
does not implement the Default
trait it would cause a compile error.
What was wrong?
see #731
How was it fixed?
Added array repeat expressions and checks for initialization of structs and arrays.
To-Do