solidity icon indicating copy to clipboard operation
solidity copied to clipboard

Remove support for the catch all (*) in the using statement

Open axic opened this issue 4 years ago • 8 comments

Does the using MyLIb for *; statement saves that much typing/space as opposed to clearly typing out the intended types?

axic avatar Sep 01 '21 16:09 axic

There are some types you cannot name but for which you can add still functions with *. Most notably literals:

library Math {
    function add(uint a, uint b) internal returns (uint) {
        return a + b;
    }
}

contract C {
    using Math for uint;
    function f() public returns (uint) { return 2.add(2); } // Error: Member "add" not found or not visible after argument-dependent lookup in int_const 2.
}

contract D {
    using Math for *;
    function f() public returns (uint) { return 2.add(2); } // OK
}

cameel avatar Sep 01 '21 17:09 cameel

I think that should be solved in a nicer way (i.e. having a rationalnumber type), than this abuse :)

axic avatar Sep 01 '21 17:09 axic

Agreed. I think that * is a bad practice in general. Just wanted to point out we probably cannot remove it without providing a replacement for this. Unless it turns out that no one knows about this trick and therefore no one uses it :)

cameel avatar Sep 01 '21 17:09 cameel

Unless it turns out that no one knows about this trick and therefore no one uses it :)

Now they certainly know about it 😅

axic avatar Sep 01 '21 17:09 axic

I'm fine with requiring to be explicit, but maybe we should ask if this breaks anything.

chriseth avatar Sep 06 '21 13:09 chriseth

Oh and we should allow ... for {uint, string}; in this case, i.e. providing a list of types.

chriseth avatar Sep 06 '21 13:09 chriseth

Oh and we should allow ... for {uint, string}; in this case, i.e. providing a list of types.

That probably is a good idea.

axic avatar Sep 06 '21 21:09 axic

We should/could check if implicit conversions are still possible on the self type as long as all types are explicitly listed in the using statment, i.e. using L.add for {uint8, uint16, ...}; allows a single implementation of the SafeMath add function.

chriseth avatar Sep 08 '21 12:09 chriseth

This issue has been marked as stale due to inactivity for the last 90 days. It will be automatically closed in 7 days.

github-actions[bot] avatar Mar 21 '23 12:03 github-actions[bot]