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() {

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

contract separate {
    derived myBase;

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

    function doStuff() {

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 Answer 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.
    – SCBuergel
    Nov 4, 2017 at 4:13
  • You are welcome, I like a challenge :D
    – Cyberience
    Nov 7, 2017 at 2:36

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.