diff --git a/Changelog.md b/Changelog.md index f162a4d0a..44ff1e913 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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) diff --git a/libsolidity/analysis/OverrideChecker.cpp b/libsolidity/analysis/OverrideChecker.cpp index d342ab100..7d6456629 100644 --- a/libsolidity/analysis/OverrideChecker.cpp +++ b/libsolidity/analysis/OverrideChecker.cpp @@ -933,7 +933,7 @@ OverrideChecker::OverrideProxyBySignatureMultiSet const& OverrideChecker::inheri { set 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()) diff --git a/test/libsolidity/semanticTests/scoping/private_function_vs_free_function.sol b/test/libsolidity/semanticTests/scoping/private_function_vs_free_function.sol new file mode 100644 index 000000000..003c7a68c --- /dev/null +++ b/test/libsolidity/semanticTests/scoping/private_function_vs_free_function.sol @@ -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 diff --git a/test/libsolidity/semanticTests/scoping/private_function_vs_inheritance.sol b/test/libsolidity/semanticTests/scoping/private_function_vs_inheritance.sol new file mode 100644 index 000000000..b62992bed --- /dev/null +++ b/test/libsolidity/semanticTests/scoping/private_function_vs_inheritance.sol @@ -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 diff --git a/test/libsolidity/semanticTests/scoping/private_function_vs_library.sol b/test/libsolidity/semanticTests/scoping/private_function_vs_library.sol new file mode 100644 index 000000000..190fecb9f --- /dev/null +++ b/test/libsolidity/semanticTests/scoping/private_function_vs_library.sol @@ -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 diff --git a/test/libsolidity/semanticTests/scoping/private_function_vs_overloading.sol b/test/libsolidity/semanticTests/scoping/private_function_vs_overloading.sol new file mode 100644 index 000000000..b74ed1f0e --- /dev/null +++ b/test/libsolidity/semanticTests/scoping/private_function_vs_overloading.sol @@ -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 diff --git a/test/libsolidity/syntaxTests/inheritance/overloaded_private_function.sol b/test/libsolidity/syntaxTests/inheritance/overloaded_private_function.sol new file mode 100644 index 000000000..c241e73e5 --- /dev/null +++ b/test/libsolidity/syntaxTests/inheritance/overloaded_private_function.sol @@ -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"? diff --git a/test/libsolidity/syntaxTests/inheritance/override/implement_private_function_by_public_variable.sol b/test/libsolidity/syntaxTests/inheritance/override/implement_private_function_by_public_variable.sol index f78403d15..a8b1acff5 100644 --- a/test/libsolidity/syntaxTests/inheritance/override/implement_private_function_by_public_variable.sol +++ b/test/libsolidity/syntaxTests/inheritance/override/implement_private_function_by_public_variable.sol @@ -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. diff --git a/test/libsolidity/syntaxTests/inheritance/override/override_private_function.sol b/test/libsolidity/syntaxTests/inheritance/override/override_private_function.sol new file mode 100644 index 000000000..0866597ca --- /dev/null +++ b/test/libsolidity/syntaxTests/inheritance/override/override_private_function.sol @@ -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. diff --git a/test/libsolidity/syntaxTests/inheritance/override/virtual_private.sol b/test/libsolidity/syntaxTests/inheritance/override/virtual_private.sol index 4fa8167c1..2102af5c3 100644 --- a/test/libsolidity/syntaxTests/inheritance/override/virtual_private.sol +++ b/test/libsolidity/syntaxTests/inheritance/override/virtual_private.sol @@ -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. diff --git a/test/libsolidity/syntaxTests/inheritance/shadowing_private_base_function.sol b/test/libsolidity/syntaxTests/inheritance/shadowing_private_base_function.sol new file mode 100644 index 000000000..99c2e2ac6 --- /dev/null +++ b/test/libsolidity/syntaxTests/inheritance/shadowing_private_base_function.sol @@ -0,0 +1,10 @@ +contract A { + function foo() private {} +} +contract B is A { + function foo() private {} +} +contract C is B { + function foo() public {} +} +// ---- diff --git a/test/libsolidity/syntaxTests/scoping/double_private_function_declaration.sol b/test/libsolidity/syntaxTests/scoping/double_private_function_declaration.sol new file mode 100644 index 000000000..b2e032bbb --- /dev/null +++ b/test/libsolidity/syntaxTests/scoping/double_private_function_declaration.sol @@ -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.