Skip to content

Instantly share code, notes, and snippets.

@a2468834
Created April 17, 2022 20:57
Show Gist options
  • Save a2468834/6fb4633c4de8cc87f3b90392f286435d to your computer and use it in GitHub Desktop.
Save a2468834/6fb4633c4de8cc87f3b90392f286435d to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.1;
contract A {
function method() public pure virtual returns (string memory) {
return "A";
}
}
contract B is A {
function method() public pure virtual override returns (string memory) {
return "B";
}
}
contract C is B {
function method() public pure override returns (string memory) {
return "C";
}
function foo1() public pure returns (string memory) {
return method();
// Cause: The most derived contract is C
// Return: "C"
// Use: JUMP
}
function foo2() public pure returns (string memory) {
return C.method();
// Cause: You explicitly specify the contract C
// Return: "C"
// Use: JUMP
}
function foo3() public pure returns (string memory) {
return super.method();
// Cause: The 1-level higher up in the inheritance hierarchy is contract B
// Return: "B"
// Use: JUMP
}
/* Error semantics
function foo4() public pure returns (string memory) {
return super.(super.method());
}
*/
function foo5() public pure returns (string memory) {
return B.method();
// Cause: You explicitly specify the inherited parent contract B
// Return: "B"
// Use: JUMP
}
function foo6() public pure returns (string memory) {
return A.method();
// Cause: You explicitly specify the inheritance parent contract A
// Return: "A"
// Use: JUMP
}
function foo7() public view returns (string memory) {
return this.method();
// Cause: Call other contract
// Return: "C"
// Use: STATICCALL
}
function foo8() public view returns (string memory) {
return C(address(this)).method();
// Cause: Call other contract
// Return: "C"
// Use: STATICCALL
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment