When using the using foo for type syntax, the methods of a type will return an empty tuple instead of the explicit type defined within the library. Why?

Currently using Solc v0.3.2.


library foo {
    // Should Return a string
    function greet(string storage self) returns (string) {
        return "Hello";

contract Greeter {

    using foo for string;
    string name = "lary";

    function say() constant returns (string) {
        return name.greet();


// Error: Different number of arguments in return statement 
// name.greet => type function (string storage pointer) returns ()

This is not a problem of libraries in themselves, but a general problem with the Ethereum virtual machine: It is practically impossible to return data of variable size in external function calls.

Having said that, we are just about to merge a change this week that might help you: If you change the library function to internal, your function will work. What will happen behind the scenes is that the call to greet will be converted from an external function call into an internal function call (where returning variably-sized data is possible because memory is not cleared between the calls). This has a drawback, though: For this to be possible, the library function code will be compiled into the calling contract, which is something you might want to avoid especially for large functions.

  • Thank you for following up, I didn't see the solidity docs mention anything about this, shouldn't this be an issue?
    – latrasis
    May 4 '16 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.