3

I have created structure with 16 elements and received solidity compiler error.

Exception during compilation: /src/libsolidity/../libevmasm/Instruction.h(217): Throw in function dev::solidity::Instruction dev::solidity::swapInstruction(unsigned int) Dynamic exception type: N5boost16exception_detail10clone_implIN3dev8solidity13InvalidOpcodeEEE std::exception::what: InvalidOpcode [PN3dev11tag_commentE] = Invalid SWAP instruction requested.

How do you get around situation like this? The contract compiles fine if structure has 15 or less elements.

I was thinking about storing multiple values in form of JSON string in one variable, but this gets cumbersome as each datatype has to be first converted to bytes and then it can be concatenated.

Any ideas?

3

This is likely similar to the stack too deep error, which is thrown when creating 16 or more local variables in a given function:

Error while compiling: Stack too deep

The advice in that case was to split the function into several smaller ones. One option, if appropriate, would be to follow the same pattern: split the structure into several (two?) smaller ones.

  • I did create another structure and declared one field of the original structure as the type of new structure. Although I don't get that error anymore while compiling, function which references this structure doesn't appear to execute. The block explorer shows function as successfully executed thought. If I try to execute this function in MIST, I get the message that this call will probably fail and use all provided gas. It is possible that MIST analyses this dependence. – Bogdan Oct 18 '16 at 16:33
  • Actually I have referenced second structure from the same function not tied to the first structure and from within the MIST I get the same error. It is telling me it will use all provided gas. I guess the only way is to store multiple values in one variable. – Bogdan Oct 18 '16 at 18:01

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.