0

I have the following smart contracts:

pragma solidity ^0.4.11;

contract base {
    uint public v;
    separate public mySep;

    function base() {
        mySep = new separate();
    }

    function f() {
        v = 1;
    }

    function sepCall() {
        mySep.doStuff();
    }
}

contract derived is base{
    function f() {
        v = 2;
        super.f();
    }
}

contract separate {
    derived myBase;

    function separate() {
        // constructor expects to be called by base or derived
        myBase = derived(msg.sender);
    }

    function doStuff() {
        myBase.f();
    }
}

I only create an instance of derived which I expect to do the following:

  1. call base constructor base()
  2. base constructor creates instance mySep of separate contract

Now I am calling sepCall of that derived instance which I expected to do the following:

  1. it calls the doStuff function of the separate contract.
  2. the doStuff calls the overridden function f of the derived contract (since that's its type)

The last point is not happening, after calling sepCall of the derived instance its value v is 1 and not 2 which it would be if the overridden function of derived would have been called.

This might not be solidity related but a general JS issue but I'd like to find out how I could make sepCall invoke the overridden function f that sets v to 2.

1

Reading your code, V = 1, because after you set V=2 you then call super.f() which sets it to 1.

  • thank you for solving this fake mystery! Then indeed everything behaves as expected. – Validity Labs - Sebastian Nov 4 '17 at 4:13
  • You are welcome, I like a challenge :D – Cyberience Nov 7 '17 at 2:36

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.