aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-07-04 04:49:02 +0800
committerGitHub <noreply@github.com>2018-07-04 04:49:02 +0800
commit533d5d4b1cc4374decc704de8c86ad4cef6214fc (patch)
treee4b053a8c1ce438d199c53fff6a5a71dab7298dc
parent16f8c23aa01ae9472088e46224dd089153540291 (diff)
parent8747079746c1ca78dfabaca22bf1c011a342bb97 (diff)
downloaddexon-solidity-533d5d4b1cc4374decc704de8c86ad4cef6214fc.tar.gz
dexon-solidity-533d5d4b1cc4374decc704de8c86ad4cef6214fc.tar.zst
dexon-solidity-533d5d4b1cc4374decc704de8c86ad4cef6214fc.zip
Merge pull request #4379 from ethereum/constructorArgsTwice
Disallow constructor arguments given multiple times.
-rw-r--r--Changelog.md1
-rw-r--r--libsolidity/analysis/TypeChecker.cpp19
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp28
-rw-r--r--test/libsolidity/syntaxTests/inheritance/base_arguments_multiple_inheritance.sol2
-rw-r--r--test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/ancestor.sol2
-rw-r--r--test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base.sol2
-rw-r--r--test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi.sol4
-rw-r--r--test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor.sol2
-rw-r--r--test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor_modifier_style.sol2
-rw-r--r--test/libsolidity/syntaxTests/modifiers/base_constructor_double_invocation.sol2
10 files changed, 20 insertions, 44 deletions
diff --git a/Changelog.md b/Changelog.md
index b2351822..b36bec2e 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -30,6 +30,7 @@ Breaking Changes:
* Parser: Remove ``constant`` as function state mutability modifer.
* Type Checker: Disallow arithmetic operations for boolean variables.
* Type Checker: Disallow conversions between ``bytesX`` and ``uintY`` of different size.
+ * Type Checker: Disallow specifying base constructor arguments multiple times in the same inheritance hierarchy. This was already the case in the experimental 0.5.0 mode.
* Type Checker: Only accept a single ``bytes`` type for ``.call()`` (and family), ``keccak256()``, ``sha256()`` and ``ripemd160()``.
* Remove obsolete ``std`` directory from the Solidity repository. This means accessing ``https://github.com/ethereum/soldity/blob/develop/std/*.sol`` (or ``https://github.com/ethereum/solidity/std/*.sol`` in Remix) will not be possible.
* Syntax Checker: Named return values in function types are an error.
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index b9e3f8d0..3bd0b4c1 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -335,8 +335,6 @@ void TypeChecker::annotateBaseConstructorArguments(
ASTNode const* _argumentNode
)
{
- bool const v050 = _currentContract.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050);
-
solAssert(_baseConstructor, "");
solAssert(_argumentNode, "");
@@ -365,18 +363,11 @@ void TypeChecker::annotateBaseConstructorArguments(
ssl.append("Second constructor call is here: ", previousNode->location());
}
- if (v050)
- m_errorReporter.declarationError(
- *mainLocation,
- ssl,
- "Base constructor arguments given twice."
- );
- else
- m_errorReporter.warning(
- *mainLocation,
- "Base constructor arguments given twice.",
- ssl
- );
+ m_errorReporter.declarationError(
+ *mainLocation,
+ ssl,
+ "Base constructor arguments given twice."
+ );
}
}
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 31842777..9e6aa43d 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -2783,24 +2783,6 @@ BOOST_AUTO_TEST_CASE(virtual_function_usage_in_constructor_arguments)
ABI_CHECK(callContractFunction("getA()"), encodeArgs(2));
}
-BOOST_AUTO_TEST_CASE(constructor_argument_overriding)
-{
- char const* sourceCode = R"(
- contract BaseBase {
- uint m_a;
- constructor(uint a) {
- m_a = a;
- }
- }
- contract Base is BaseBase(2) { }
- contract Derived is BaseBase(3), Base {
- function getA() returns (uint r) { return m_a; }
- }
- )";
- compileAndRun(sourceCode, 0, "Derived");
- ABI_CHECK(callContractFunction("getA()"), encodeArgs(3));
-}
-
BOOST_AUTO_TEST_CASE(internal_constructor)
{
char const* sourceCode = R"(
@@ -5521,10 +5503,10 @@ BOOST_AUTO_TEST_CASE(pass_dynamic_arguments_to_the_base_base)
uint public m_i;
}
contract Base1 is Base {
- constructor(uint k) Base(k*k) {}
+ constructor(uint k) Base(k) {}
}
contract Derived is Base, Base1 {
- constructor(uint i) Base(i) Base1(i)
+ constructor(uint i) Base1(i)
{}
}
contract Final is Derived(4) {
@@ -5544,9 +5526,11 @@ BOOST_AUTO_TEST_CASE(pass_dynamic_arguments_to_the_base_base_with_gap)
}
uint public m_i;
}
- contract Base1 is Base(3) {}
+ contract Base1 is Base {
+ constructor(uint k) {}
+ }
contract Derived is Base, Base1 {
- constructor(uint i) Base(i) {}
+ constructor(uint i) Base(i) Base1(7) {}
}
contract Final is Derived(4) {
}
diff --git a/test/libsolidity/syntaxTests/inheritance/base_arguments_multiple_inheritance.sol b/test/libsolidity/syntaxTests/inheritance/base_arguments_multiple_inheritance.sol
index 015b33e5..96be62f2 100644
--- a/test/libsolidity/syntaxTests/inheritance/base_arguments_multiple_inheritance.sol
+++ b/test/libsolidity/syntaxTests/inheritance/base_arguments_multiple_inheritance.sol
@@ -6,4 +6,4 @@ contract Derived is Base, Base1 {
constructor(uint i) Base(i) public {}
}
// ----
-// Warning: (138-145): Base constructor arguments given twice.
+// DeclarationError: (138-145): Base constructor arguments given twice.
diff --git a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/ancestor.sol b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/ancestor.sol
index 24cff54d..76cc937b 100644
--- a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/ancestor.sol
+++ b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/ancestor.sol
@@ -2,4 +2,4 @@ contract A { constructor(uint) public { } }
contract B is A(2) { constructor() public { } }
contract C is B { constructor() A(3) public { } }
// ----
-// Warning: (125-129): Base constructor arguments given twice.
+// DeclarationError: (125-129): Base constructor arguments given twice.
diff --git a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base.sol b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base.sol
index 9ceaea5e..4c7a684f 100644
--- a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base.sol
+++ b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base.sol
@@ -1,4 +1,4 @@
contract A { constructor(uint) public { } }
contract B is A(2) { constructor() A(3) public { } }
// ----
-// Warning: (79-83): Base constructor arguments given twice.
+// DeclarationError: (79-83): Base constructor arguments given twice.
diff --git a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi.sol b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi.sol
index e5c2aa36..2e77e077 100644
--- a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi.sol
+++ b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi.sol
@@ -3,5 +3,5 @@ contract A is C(2) {}
contract B is C(2) {}
contract D is A, B { constructor() C(3) public {} }
// ----
-// Warning: (122-126): Base constructor arguments given twice.
-// Warning: (122-126): Base constructor arguments given twice.
+// DeclarationError: (122-126): Base constructor arguments given twice.
+// DeclarationError: (122-126): Base constructor arguments given twice.
diff --git a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor.sol b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor.sol
index 1abf2992..0beb1552 100644
--- a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor.sol
+++ b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor.sol
@@ -3,4 +3,4 @@ contract A is C(2) {}
contract B is C(2) {}
contract D is A, B {}
// ----
-// Warning: (87-108): Base constructor arguments given twice.
+// DeclarationError: (87-108): Base constructor arguments given twice.
diff --git a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor_modifier_style.sol b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor_modifier_style.sol
index e15242db..7142840e 100644
--- a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor_modifier_style.sol
+++ b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor_modifier_style.sol
@@ -3,4 +3,4 @@ contract A is C { constructor() C(2) public {} }
contract B is C { constructor() C(2) public {} }
contract D is A, B { }
// ----
-// Warning: (141-163): Base constructor arguments given twice.
+// DeclarationError: (141-163): Base constructor arguments given twice.
diff --git a/test/libsolidity/syntaxTests/modifiers/base_constructor_double_invocation.sol b/test/libsolidity/syntaxTests/modifiers/base_constructor_double_invocation.sol
index bdbab5d8..49d0d7bf 100644
--- a/test/libsolidity/syntaxTests/modifiers/base_constructor_double_invocation.sol
+++ b/test/libsolidity/syntaxTests/modifiers/base_constructor_double_invocation.sol
@@ -3,5 +3,5 @@ contract B is C {
constructor() C(2) C(2) public {}
}
// ----
-// Warning: (81-85): Base constructor arguments given twice.
+// DeclarationError: (81-85): Base constructor arguments given twice.
// DeclarationError: (86-90): Base constructor already provided.