I'm wondering why if my function is meant to return a string of indeterminate length, I can't return a string array of definite length.

This function, for example doesn't compile

function BindingTypeList() public pure returns(string[]  memory) {
        return ["DocumentTemplate", "Definition", "RepAndWarranty", "Restriction", "Entitlement"];

the error message is TypeError: Return argument type string memory[5] memory is not implicitly convertible to expected type (type of first return variable) string memory[] memory.

It seems like they are saying that string[5] is incompatible with returns(string[]). I don't get that at all.

2 Answers 2


In case others have this problem the way it can be done is:

function BindingTypeList() public pure returns(string[]  memory) {
   string[] memory names = new string[5];
   names[0] = "DocumentTemplate";
   names[1] = "Definition";
   names[4] = "Entitlement";
   return names;

you need to use pragma experimental ABIEncoderV2; in your contract to enable returning the array of strings.

  • Actually not, at least not in >8.0.0. I think it is no longer experimental.
    – GGizmos
    Sep 23, 2021 at 0:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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