1

Question in one sentence:

Regarding function calls, to infer the what the most derived function is, is it enough to track functions in base contracts for each contract, or do we also have to consider the final inheritance graph?

An example below clarifies my question:

contract B {
    function testb() public{ }
}
contract C{
    function testc() public{ }
}

contract D is B,C {
    function testd() public{ }
}

In the above code, are no functions copied into the contract C? Or, should the function testb in contract B be copied into the contract C as the final inheritance graph is D->C->B?

Solidity docs says that:

the code from all the base contracts is copied into the created contract.

Based on the description above, it seems that no functions may be copied into the contract C, as the C has no base contracts.

However, I am still confused because I do not know when we have to consider final inheritance graph. Solidity docs explains only one such case (super call).

  • 1
    Solidity uses C3 linearization: solidity.readthedocs.io/en/v0.4.25/…. – smarx Nov 4 '18 at 11:09
  • as the final inheritance graph is D->C->B - this is not the final inheritance graph in your coding example (contract C does not inherit from contract B). – goodvibration Nov 4 '18 at 14:08
  • @RobHitchensB9lab I did not understand your intention. D can be deployed and I again confirmed it by testing the code in Remix. – Sunbeom So Nov 4 '18 at 14:22
  • @goodvibration Supposing the contract D is deployed, the final inheritance graph is D->C->B. – Sunbeom So Nov 4 '18 at 14:24
  • @goodvibration. You're right. My mistake eyeballing it. – Rob Hitchens - B9lab Nov 4 '18 at 14:30
0

Or, should the function testb in contract B be copied into the contract C as the final inheritance graph is D->C->B?

This isn't what your code example shows. D inherits from both C and B, but C doesn't inherit from B. The answer though is that all 3 functions will be present in D, but C & B will only have the functions defined within them.

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.