mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Fix inheritedFunctions returns private functions
OverrideChecker treated private functions as inheritable. Hence, a child contract function could not be assigned the function name of a parent contract private function.
This commit is contained in:
parent
95bc553ffc
commit
1276c43ad8
@ -13,6 +13,7 @@ Compiler Features:
|
||||
Bugfixes:
|
||||
* Commandline Interface: Disallow the following options outside of the compiler mode: ``--via-ir``,``--metadata-literal``, ``--metadata-hash``, ``--model-checker-show-unproved``, ``--model-checker-div-mod-no-slacks``, ``--model-checker-engine``, ``--model-checker-invariants``, ``--model-checker-solvers``, ``--model-checker-timeout``, ``--model-checker-contracts``, ``--model-checker-targets``.
|
||||
* Type Checker: Fix null dereference in `abi.encodeCall` type checking of free function.
|
||||
* Override Checker: Fix `inheritedFunctions` returns private functions.
|
||||
|
||||
|
||||
### 0.8.15 (2022-06-15)
|
||||
|
@ -933,7 +933,7 @@ OverrideChecker::OverrideProxyBySignatureMultiSet const& OverrideChecker::inheri
|
||||
{
|
||||
set<OverrideProxy, OverrideProxy::CompareBySignature> functionsInBase;
|
||||
for (FunctionDefinition const* fun: base->definedFunctions())
|
||||
if (!fun->isConstructor())
|
||||
if (!fun->isConstructor() && fun->visibility() != Visibility::Private)
|
||||
functionsInBase.emplace(OverrideProxy{fun});
|
||||
for (VariableDeclaration const* var: base->stateVariables())
|
||||
if (var->isPublic())
|
||||
|
@ -0,0 +1,10 @@
|
||||
function foo(uint256 value) pure returns (uint256) { return 1; }
|
||||
contract A {
|
||||
function foo(uint256 value) private pure returns (uint256) { return 2; }
|
||||
}
|
||||
contract B is A {
|
||||
using {foo} for uint256;
|
||||
function test(uint256 value) public pure returns (uint256) { return value.foo(); }
|
||||
}
|
||||
// ----
|
||||
// test(uint256): 0 -> 1
|
@ -0,0 +1,16 @@
|
||||
contract A {
|
||||
function foo() private pure returns (uint256) { return 1; }
|
||||
function bar() internal pure returns (uint256) { return foo(); }
|
||||
}
|
||||
contract B is A {
|
||||
function foo() private pure returns (uint256) { return 2; }
|
||||
function test1() public pure returns (uint256) { return bar(); }
|
||||
function test2() public pure returns (uint256) { return foo(); }
|
||||
}
|
||||
contract C is B {
|
||||
function foo() public pure returns (uint256) { return 3; }
|
||||
}
|
||||
// ----
|
||||
// test1() -> 1
|
||||
// test2() -> 2
|
||||
// foo() -> 3
|
@ -0,0 +1,17 @@
|
||||
library L {
|
||||
function foo(uint256 value) private pure returns (uint256) { return 1; }
|
||||
function bar(uint256 value) public pure returns (uint256) { return foo(value); }
|
||||
}
|
||||
contract A {
|
||||
function foo(uint256 value) private pure returns (uint256) { return 2; }
|
||||
}
|
||||
contract B is A {
|
||||
using L for uint256;
|
||||
function foo(uint256 value) private pure returns (uint256) { return 3; }
|
||||
function test(uint256 value) public pure returns (uint256) { return value.bar(); }
|
||||
}
|
||||
// ====
|
||||
// compileToEwasm: false
|
||||
// ----
|
||||
// library: L
|
||||
// test(uint256): 0 -> 1
|
@ -0,0 +1,17 @@
|
||||
contract A {
|
||||
function foo() private pure returns (uint256) { return 1; }
|
||||
function foo(uint256 value) private pure returns (uint256) { return 2; }
|
||||
function test1() public pure returns (uint256) { return foo(); }
|
||||
function test2() public pure returns (uint256) { return foo(0); }
|
||||
}
|
||||
contract B is A {
|
||||
function foo() private pure returns (uint256) { return 3; }
|
||||
function foo(uint256 value) private pure returns (uint256) { return 4; }
|
||||
function test3() public pure returns (uint256) { return foo(); }
|
||||
function test4() public pure returns (uint256) { return foo(0); }
|
||||
}
|
||||
// ----
|
||||
// test1() -> 1
|
||||
// test2() -> 2
|
||||
// test3() -> 3
|
||||
// test4() -> 4
|
@ -0,0 +1,12 @@
|
||||
contract A {
|
||||
function foo() private {}
|
||||
function foo(uint128 value) private {}
|
||||
function foo(uint256 value) public {}
|
||||
}
|
||||
contract B is A {
|
||||
function foo(uint128 value) private {}
|
||||
function foo(uint256 value) public {}
|
||||
}
|
||||
// ----
|
||||
TypeError 9456: (195-232): Overriding function is missing "override" specifier.
|
||||
TypeError 4334: (90-127): Trying to override non-virtual function. Did you forget to add "virtual"?
|
@ -6,5 +6,5 @@ contract T {
|
||||
constructor() { new Y(); }
|
||||
}
|
||||
// ----
|
||||
// TypeError 5225: (97-130): Public state variables can only override functions with external visibility.
|
||||
// TypeError 7792: (112-120): Public state variable has override specified but does not override anything.
|
||||
// TypeError 3942: (22-72): "virtual" and "private" cannot be used together.
|
||||
|
@ -0,0 +1,8 @@
|
||||
contract A {
|
||||
function foo() private {}
|
||||
}
|
||||
contract B is A {
|
||||
function foo() private override {}
|
||||
}
|
||||
// ----
|
||||
// TypeError 7792: (84-92): Function has override specified but does not override anything.
|
@ -5,4 +5,5 @@ abstract contract X is A {
|
||||
function test() private override returns (uint256) {}
|
||||
}
|
||||
// ----
|
||||
// TypeError 7792: (128-136): Function has override specified but does not override anything.
|
||||
// TypeError 3942: (23-73): "virtual" and "private" cannot be used together.
|
||||
|
@ -0,0 +1,10 @@
|
||||
contract A {
|
||||
function foo() private {}
|
||||
}
|
||||
contract B is A {
|
||||
function foo() private {}
|
||||
}
|
||||
contract C is B {
|
||||
function foo() public {}
|
||||
}
|
||||
// ----
|
@ -0,0 +1,6 @@
|
||||
contract A {
|
||||
function foo() private {}
|
||||
function foo() private {}
|
||||
}
|
||||
// ----
|
||||
// DeclarationError 1686: (14-39): Function with same name and parameter types defined twice.
|
Loading…
Reference in New Issue
Block a user