-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Allow multi-variable declaration for tuple assignment to use explicit types. #3520
Comments
Are the surrounding parentheses necessary? |
Not sure, we always had them to make the tuples explicit. |
Also it might be confusing for people coming from C or JavaScript (because there, |
This is not true, it is only true in conjunction with the disallow-uninitalised-storage-pointers and only affects types/variables residing int storage. Probably a better example would be one using such a case. |
I would say that
already counts as "not easy". |
Yeah, I'm coming from Ruby where this is valid:
|
This post was exactly what I was looking for! In all the Ethereum examples, the "var" keyword is used when you want to assign values to a tuple function (e.g. var (x,y) = f() ). Since "var" is now deprecated, how should a multi variable assignment be done? |
I just found the solution (credits to: https://ethereum.stackexchange.com/questions/21348/get-the-return-of-a-function-with-multiple-returns)
The following is also supported in case you're only interested in
|
To be clear: The grammer of a tuple expression should consequently be changed from
to
? |
No, probably not. I guess it makes more sense to change |
So changing
to
is probably more like what we want? |
Should the assignment be required for multi-variable declarations or should
be valid as well? |
If the assignment should be required, that would probably mean
|
A potential option would be:
@axic just said we should postpone and further discuss this, though. |
I would say that assignment is required, otherwise it is just weird, even if this adds a special case. |
I am not fully convinced this is a problem to be solved. One benefit of not having it is the visual clarity that new variables are declared, whereas in a tuple declaration they would be less visible. |
It is kind of the same discussion whether we should have multiple variable declarations on the same line or not. Currently we do not support that. |
@ekpyron I think |
I think singleton tuples and tuple types are out of scope for this discussion. They are currently both possible, the latter is just not nameable. We certainly should disallow catch-all tuple components, but that is also addressed in a different issue. While |
And further in the future, substitute |
Can we have some actual examples where this feature is badly needed? |
@chriseth I'm not sure whether However |
@axic Ultimately it's a convenience feature, so I don't think there's cases in which it is really badly needed... However, I think it may be worth considering, whether promoting tuple types to first-class types that can actually be named rather than only having them somewhat implicitly in assignments and function returns, wouldn't be cleaner in general... |
Yeah, it's probably true that this is only badly needed in cases where the types cannot be named anyway. |
Ah right, if one of the variables is a storage pointer, it might be very hard to refactor the warning away, and it might require multiple storage reads. |
If we introduce tuple types, I would probably prefer somethnig like In general, I still think that most solidity users would find |
I think somewhat relevant is the discussion on how restricted variable declarations are at the moment: they do not allow multiple declarations (with or without value assignment) in the same statement. If those are like that, why is tuple declaration an exception? I do not mean any of this is good or bad, but worth looking at the bigger picture. |
I don't see the difference between a tuple declaration and the declaration of multiple variables in the same statement. You can declare multiple variables in the same statement, you just need to add parentheses. |
What do you mean by that? Do you have an example? |
Of course you need var because I was too lazy to change the parser accordingly back in the days: |
Since |
Yes, exactly. It should be possible to assign function return values to newly declared variables because a variable declaration with assignment looks safer (and probably is) than without. |
Not talking about function return values, but actual variable declarations. |
Yes, the declaration of multiple variables in the same statement without assigning values is redundant and can be removed. |
For me this feature is a plus, because I can follow the single assignment style. Without this feature, I have to write
With this feature, I can write
So, each of |
Expanded the only case zeppelin does multi return values into the options discussed above:
|
Most of the use-cases will probably cease being use-cases when we have support for structs... |
Discussion: let's go with the original proposal for now and try to make breaking releases more often. |
With the deprecation of var, it is not possible anymore to easily assign the result of a function to local variables. We should allow types to be specified in such assignments:
The text was updated successfully, but these errors were encountered: