mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add more override tests with public state variables
This commit is contained in:
parent
70623665bf
commit
1fb62b91d2
@ -26,6 +26,7 @@
|
||||
#include <libsolidity/analysis/TypeChecker.h>
|
||||
#include <liblangutil/ErrorReporter.h>
|
||||
#include <libdevcore/Visitor.h>
|
||||
|
||||
#include <boost/range/adaptor/reversed.hpp>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
|
||||
@ -490,7 +491,7 @@ void OverrideChecker::checkOverride(OverrideProxy const& _overriding, OverridePr
|
||||
);
|
||||
|
||||
if (!_overriding.overrides())
|
||||
overrideError(_overriding, _super, "Overriding " + _overriding.astNodeName() + " is missing 'override' specifier.");
|
||||
overrideError(_overriding, _super, "Overriding " + _overriding.astNodeName() + " is missing \"override\" specifier.");
|
||||
|
||||
if (_super.isVariable())
|
||||
overrideError(
|
||||
@ -571,7 +572,7 @@ void OverrideChecker::overrideListError(
|
||||
for (Declaration const* c: _secondary)
|
||||
{
|
||||
ssl.append("This contract: ", c->location());
|
||||
names.insert(c->name());
|
||||
names.insert("\"" + c->name() + "\"");
|
||||
}
|
||||
string contractSingularPlural = "contract ";
|
||||
if (_secondary.size() > 1)
|
||||
|
@ -5,4 +5,4 @@ contract D is C {
|
||||
fallback() external {}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (66-88): Overriding function is missing 'override' specifier.
|
||||
// TypeError: (66-88): Overriding function is missing "override" specifier.
|
||||
|
@ -7,4 +7,4 @@ contract E is D {
|
||||
fallback() external {}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (86-108): Overriding function is missing 'override' specifier.
|
||||
// TypeError: (86-108): Overriding function is missing "override" specifier.
|
||||
|
@ -5,4 +5,4 @@ contract D is C {
|
||||
receive() external payable {}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (73-102): Overriding function is missing 'override' specifier.
|
||||
// TypeError: (73-102): Overriding function is missing "override" specifier.
|
||||
|
@ -7,4 +7,4 @@ contract E is D {
|
||||
receive() external payable {}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (93-122): Overriding function is missing 'override' specifier.
|
||||
// TypeError: (93-122): Overriding function is missing "override" specifier.
|
||||
|
@ -1,5 +1,5 @@
|
||||
contract B { function f() virtual public {} }
|
||||
contract C is B { function f() public view {} }
|
||||
// ----
|
||||
// TypeError: (64-91): Overriding function is missing 'override' specifier.
|
||||
// TypeError: (64-91): Overriding function is missing "override" specifier.
|
||||
// TypeError: (64-91): Overriding function changes state mutability from "nonpayable" to "view".
|
||||
|
@ -7,5 +7,5 @@ contract B is I {
|
||||
function f() public pure returns (uint, uint) {}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (182-230): Overriding function is missing 'override' specifier.
|
||||
// TypeError: (182-230): Overriding function is missing "override" specifier.
|
||||
// TypeError: (182-230): Overriding function return types differ.
|
||||
|
@ -0,0 +1,13 @@
|
||||
interface I {
|
||||
}
|
||||
contract A is I
|
||||
{
|
||||
uint public f;
|
||||
}
|
||||
abstract contract B is I
|
||||
{
|
||||
function f() external virtual returns (uint);
|
||||
}
|
||||
abstract contract C is A, B {}
|
||||
// ----
|
||||
// TypeError: (128-158): Derived contract must override function "f". Two or more base classes define function with same name and parameter types. Since one of the bases defines a public state variable which cannot be overridden, you have to change the inheritance layout or the names of the functions.
|
@ -0,0 +1,12 @@
|
||||
interface I {
|
||||
function f() external returns (uint);
|
||||
}
|
||||
abstract contract A is I
|
||||
{
|
||||
uint public override f;
|
||||
}
|
||||
abstract contract B is I
|
||||
{
|
||||
}
|
||||
// This is fine because `f` is not implemented in `I` and `A.f` is the only mention below `I`.
|
||||
abstract contract C is A, B {}
|
@ -0,0 +1,14 @@
|
||||
interface I {
|
||||
function f() external returns (uint);
|
||||
}
|
||||
contract A is I
|
||||
{
|
||||
uint public override f;
|
||||
}
|
||||
abstract contract B is I
|
||||
{
|
||||
function f() external virtual override returns (uint);
|
||||
}
|
||||
abstract contract C is A, B {}
|
||||
// ----
|
||||
// TypeError: (185-215): Derived contract must override function "f". Two or more base classes define function with same name and parameter types. Since one of the bases defines a public state variable which cannot be overridden, you have to change the inheritance layout or the names of the functions.
|
@ -0,0 +1,14 @@
|
||||
interface I {
|
||||
function f() external returns (uint);
|
||||
}
|
||||
contract A is I
|
||||
{
|
||||
uint public override f;
|
||||
}
|
||||
abstract contract B is I
|
||||
{
|
||||
function f() external virtual override returns (uint) { return 2; }
|
||||
}
|
||||
abstract contract C is A, B {}
|
||||
// ----
|
||||
// TypeError: (198-228): Derived contract must override function "f". Two or more base classes define function with same name and parameter types. Since one of the bases defines a public state variable which cannot be overridden, you have to change the inheritance layout or the names of the functions.
|
@ -0,0 +1,13 @@
|
||||
contract I {
|
||||
function f() external pure virtual returns (uint) { return 1; }
|
||||
}
|
||||
contract A is I
|
||||
{
|
||||
}
|
||||
contract B is I
|
||||
{
|
||||
}
|
||||
contract C is A, B
|
||||
{
|
||||
uint public override f;
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
contract I {
|
||||
function f() external pure virtual returns (uint) { return 1; }
|
||||
}
|
||||
contract A is I
|
||||
{
|
||||
uint public override f;
|
||||
}
|
||||
contract B is I
|
||||
{
|
||||
function f() external pure virtual override returns (uint) { return 2; }
|
||||
}
|
||||
contract C is A, B {}
|
||||
// ----
|
||||
// TypeError: (219-240): Derived contract must override function "f". Two or more base classes define function with same name and parameter types. Since one of the bases defines a public state variable which cannot be overridden, you have to change the inheritance layout or the names of the functions.
|
@ -0,0 +1,13 @@
|
||||
contract I {
|
||||
function f() external pure virtual returns (uint) { return 1; }
|
||||
}
|
||||
contract A is I
|
||||
{
|
||||
uint public override f;
|
||||
}
|
||||
contract B is I
|
||||
{
|
||||
}
|
||||
contract C is A, B {}
|
||||
// ----
|
||||
// TypeError: (145-166): Derived contract must override function "f". Two or more base classes define function with same name and parameter types. Since one of the bases defines a public state variable which cannot be overridden, you have to change the inheritance layout or the names of the functions.
|
@ -7,5 +7,5 @@ abstract contract X is A {
|
||||
function test2() external override(A) returns (uint256) {}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (153-198): Overriding function is missing 'override' specifier.
|
||||
// TypeError: (153-198): Overriding function is missing "override" specifier.
|
||||
// TypeError: (76-122): Trying to override non-virtual function. Did you forget to add "virtual"?
|
||||
|
@ -18,5 +18,5 @@ abstract contract X is A, B, C, D {
|
||||
function foo() internal override(A, C) virtual returns (uint256);
|
||||
}
|
||||
// ----
|
||||
// TypeError: (533-550): Invalid contract specified in override list: C.
|
||||
// TypeError: (603-617): Function needs to specify overridden contracts B and D.
|
||||
// TypeError: (533-550): Invalid contract specified in override list: "C".
|
||||
// TypeError: (603-617): Function needs to specify overridden contracts "B" and "D".
|
||||
|
@ -6,4 +6,4 @@ abstract contract X is A {
|
||||
}
|
||||
// ----
|
||||
// DeclarationError: (73-100): Identifier already declared.
|
||||
// TypeError: (84-92): Public state variable has override specified but does not override anything.
|
||||
// TypeError: (23-41): Cannot override public state variable.
|
||||
|
@ -0,0 +1,21 @@
|
||||
interface A {
|
||||
function foo() external returns (uint);
|
||||
function goo() external returns (uint);
|
||||
}
|
||||
interface B {
|
||||
function foo() external returns (uint);
|
||||
function goo() external returns (uint);
|
||||
}
|
||||
contract X is A, B {
|
||||
uint public override(A, B) foo;
|
||||
function goo() external virtual override(A, B) returns (uint) {}
|
||||
}
|
||||
abstract contract T is A {
|
||||
function foo() external virtual override returns (uint);
|
||||
function goo() external virtual override returns (uint);
|
||||
}
|
||||
contract Y is X, T {
|
||||
}
|
||||
// ----
|
||||
// TypeError: (484-506): Derived contract must override function "foo". Two or more base classes define function with same name and parameter types. Since one of the bases defines a public state variable which cannot be overridden, you have to change the inheritance layout or the names of the functions.
|
||||
// TypeError: (484-506): Derived contract must override function "goo". Two or more base classes define function with same name and parameter types.
|
@ -0,0 +1,11 @@
|
||||
interface A {
|
||||
function foo() external returns (uint);
|
||||
}
|
||||
interface B {
|
||||
function foo() external returns (uint);
|
||||
}
|
||||
contract X is A, B {
|
||||
uint public override(A) foo;
|
||||
}
|
||||
// ----
|
||||
// TypeError: (154-165): Public state variable needs to specify overridden contract "B".
|
@ -5,4 +5,5 @@ contract X is A {
|
||||
uint public foo;
|
||||
}
|
||||
// ----
|
||||
// TypeError: (100-115): Overriding public state variable is missing "override" specifier.
|
||||
// TypeError: (100-115): Public state variables can only override functions with external visibility.
|
||||
|
@ -0,0 +1,9 @@
|
||||
contract A {
|
||||
uint public foo;
|
||||
}
|
||||
contract X is A {
|
||||
uint public override foo;
|
||||
}
|
||||
// ----
|
||||
// DeclarationError: (55-79): Identifier already declared.
|
||||
// TypeError: (17-32): Cannot override public state variable.
|
@ -0,0 +1,10 @@
|
||||
interface A {
|
||||
function foo() external returns (uint);
|
||||
}
|
||||
interface B {
|
||||
function foo() external returns (uint);
|
||||
}
|
||||
contract X is A, B {
|
||||
uint public override(A, B) foo;
|
||||
}
|
||||
// ----
|
@ -0,0 +1,12 @@
|
||||
interface A {
|
||||
function foo() external returns (uint);
|
||||
}
|
||||
interface B {
|
||||
function foo() external returns (uint);
|
||||
}
|
||||
contract X is A, B {
|
||||
uint public override(A, B) foo;
|
||||
}
|
||||
contract Y is X {
|
||||
}
|
||||
// ----
|
@ -0,0 +1,10 @@
|
||||
interface A {
|
||||
function foo() external returns (uint);
|
||||
}
|
||||
contract B {
|
||||
uint public foo;
|
||||
}
|
||||
contract X is A, B {
|
||||
}
|
||||
// ----
|
||||
// TypeError: (96-118): Derived contract must override function "foo". Two or more base classes define function with same name and parameter types. Since one of the bases defines a public state variable which cannot be overridden, you have to change the inheritance layout or the names of the functions.
|
@ -0,0 +1,9 @@
|
||||
interface A {
|
||||
function foo() external returns (uint);
|
||||
}
|
||||
interface B {}
|
||||
contract X is A {
|
||||
uint public override(A, B) foo;
|
||||
}
|
||||
// ----
|
||||
// TypeError: (106-120): Invalid contract specified in override list: "B".
|
@ -8,4 +8,4 @@ contract X is A, B {
|
||||
uint public override foo;
|
||||
}
|
||||
// ----
|
||||
// TypeError: (162-211): Derived contract must override function "foo". Two or more base classes define function with same name and parameter types.
|
||||
// TypeError: (196-204): Public state variable needs to specify overridden contracts "A" and "B".
|
||||
|
@ -9,3 +9,5 @@ contract X is A, B {
|
||||
}
|
||||
// ----
|
||||
// DeclarationError: (136-160): Identifier already declared.
|
||||
// TypeError: (14-29): Cannot override public state variable.
|
||||
// TypeError: (148-156): Public state variable needs to specify overridden contracts "A" and "B".
|
||||
|
@ -11,4 +11,4 @@ contract X is B, C {
|
||||
uint public override foo;
|
||||
}
|
||||
// ----
|
||||
// TypeError: (271-320): Derived contract must override function "foo". Two or more base classes define function with same name and parameter types.
|
||||
// TypeError: (305-313): Public state variable needs to specify overridden contracts "B" and "C".
|
||||
|
@ -12,4 +12,5 @@ contract X is B, C {
|
||||
}
|
||||
// ----
|
||||
// DeclarationError: (245-269): Identifier already declared.
|
||||
// TypeError: (223-272): Derived contract must override function "foo". Two or more base classes define function with same name and parameter types.
|
||||
// TypeError: (100-124): Cannot override public state variable.
|
||||
// TypeError: (257-265): Public state variable needs to specify overridden contracts "B" and "C".
|
||||
|
@ -0,0 +1,17 @@
|
||||
contract A {
|
||||
function foo() external virtual pure returns(uint) { return 5; }
|
||||
}
|
||||
contract B is A {
|
||||
uint public override foo;
|
||||
}
|
||||
contract C is A {
|
||||
function foo() external virtual override pure returns(uint) { return 5; }
|
||||
}
|
||||
contract X is B, C {
|
||||
uint public override(A, C) foo;
|
||||
}
|
||||
// ----
|
||||
// DeclarationError: (245-275): Identifier already declared.
|
||||
// TypeError: (100-124): Cannot override public state variable.
|
||||
// TypeError: (257-271): Public state variable needs to specify overridden contract "B".
|
||||
// TypeError: (257-271): Invalid contract specified in override list: "A".
|
@ -8,4 +8,3 @@ contract X is A, B {
|
||||
uint public override(A, B) foo;
|
||||
}
|
||||
// ----
|
||||
// TypeError: (162-217): Derived contract must override function "foo". Two or more base classes define function with same name and parameter types.
|
||||
|
@ -1,5 +1,5 @@
|
||||
contract B { function f() virtual public view {} }
|
||||
contract C is B { function f() public {} }
|
||||
// ----
|
||||
// TypeError: (69-91): Overriding function is missing 'override' specifier.
|
||||
// TypeError: (69-91): Overriding function is missing "override" specifier.
|
||||
// TypeError: (69-91): Overriding function changes state mutability from "view" to "nonpayable".
|
||||
|
@ -6,3 +6,5 @@ contract C is A {
|
||||
}
|
||||
// ----
|
||||
// DeclarationError: (50-87): Identifier already declared.
|
||||
// TypeError: (50-87): Overriding function is missing "override" specifier.
|
||||
// TypeError: (14-27): Cannot override public state variable.
|
||||
|
@ -2,4 +2,4 @@ contract A { function mod(uint a) public { } }
|
||||
contract B is A { modifier mod(uint a) { _; } }
|
||||
// ----
|
||||
// DeclarationError: (65-92): Identifier already declared.
|
||||
// TypeError: (65-92): Override changes function to modifier.
|
||||
// TypeError: (65-92): Override changes function or public state variable to modifier.
|
||||
|
@ -2,5 +2,5 @@ contract A { modifier mod(uint a) { _; } }
|
||||
contract B is A { modifier mod(uint8 a) { _; } }
|
||||
// ----
|
||||
// TypeError: (61-89): Override changes modifier signature.
|
||||
// TypeError: (61-89): Overriding modifier is missing 'override' specifier.
|
||||
// TypeError: (61-89): Overriding modifier is missing "override" specifier.
|
||||
// TypeError: (13-40): Trying to override non-virtual modifier. Did you forget to add "virtual"?
|
||||
|
@ -1,5 +1,5 @@
|
||||
contract B { function f() virtual internal {} }
|
||||
contract C is B { function f() public {} }
|
||||
// ----
|
||||
// TypeError: (66-88): Overriding function is missing 'override' specifier.
|
||||
// TypeError: (66-88): Overriding function is missing "override" specifier.
|
||||
// TypeError: (66-88): Overriding function visibility differs.
|
||||
|
@ -1,5 +1,5 @@
|
||||
contract B { function f() payable virtual public {} }
|
||||
contract C is B { function f() public {} }
|
||||
// ----
|
||||
// TypeError: (72-94): Overriding function is missing 'override' specifier.
|
||||
// TypeError: (72-94): Overriding function is missing "override" specifier.
|
||||
// TypeError: (72-94): Overriding function changes state mutability from "payable" to "nonpayable".
|
||||
|
@ -1,5 +1,5 @@
|
||||
contract B { function f() virtual public {} }
|
||||
contract C is B { function f() payable public {} }
|
||||
// ----
|
||||
// TypeError: (64-94): Overriding function is missing 'override' specifier.
|
||||
// TypeError: (64-94): Overriding function is missing "override" specifier.
|
||||
// TypeError: (64-94): Overriding function changes state mutability from "nonpayable" to "payable".
|
||||
|
Loading…
Reference in New Issue
Block a user