Improved support for destructuring tuples with partially declared outputs

Hey,

Wondering about thoughts on the following

    function _tuple() internal pure returns (uint, uint) {
        return (1, 1);
    }
    
    function outer() internal pure {
        // valid
        (uint a, uint b) = _tuple();
        
        // valid
        uint c; uint d;
        (c, d) = _tuple();

        // invalid
        uint e;
        (e, uint f) = tuple();

    }

Looks to me like tuples require destructing all elements either into predefined variables, or require inline declarations for all elements.

I understand there might be practical reasons for this, and would be interested to hear them. I was expecting to be able to “mix and match” between previously declared variables and newly declared variables.

Would be interested to hear if this would be a useful change or if there are major technical hurdles behind implementing something like this?

I don’t see any technical problems with this. Other than maybe adding more possible corner cases in the compiler where things could go wrong. So it’s mostly a question of how useful would that be in practice.

I ran into it today, I wouldn’t say it’s coming up all the time but from an “expected behaviour” standpoint it took me a minute to work out what my syntax error is. Would be a nice fix depending on the time/effort required

You could submit a feature request, though I’d say that it would be very low priority for us right now so might be better to first see if more people would find that useful.

Definitely useful for me as a nice to have. Sometimes I have to declare 2 or 3 extra variables right before destructuring the tuple just so I can reuse previous variables and the code is a bit less readable. @cameel where should we do the feature request?

1 Like