diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2018-04-04 06:15:18 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-04 06:15:18 +0800 |
commit | 0695ffe51d5195dbedce37b26bbe395cfdaf3746 (patch) | |
tree | a07b20e4fd9f3c1de2fd3bf80148d210dd16545d /test | |
parent | 104a9736b35495cf50bf1a895d61aed9a1ba830a (diff) | |
parent | 3ae326139a505bed877d5b9ac9b4b3ed84496c3d (diff) | |
download | dexon-solidity-0695ffe51d5195dbedce37b26bbe395cfdaf3746.tar dexon-solidity-0695ffe51d5195dbedce37b26bbe395cfdaf3746.tar.gz dexon-solidity-0695ffe51d5195dbedce37b26bbe395cfdaf3746.tar.bz2 dexon-solidity-0695ffe51d5195dbedce37b26bbe395cfdaf3746.tar.lz dexon-solidity-0695ffe51d5195dbedce37b26bbe395cfdaf3746.tar.xz dexon-solidity-0695ffe51d5195dbedce37b26bbe395cfdaf3746.tar.zst dexon-solidity-0695ffe51d5195dbedce37b26bbe395cfdaf3746.zip |
Merge pull request #3635 from ethereum/constructor-modifier
Constructors are defined using the ``constructor`` keyword.
Diffstat (limited to 'test')
3 files changed, 34 insertions, 5 deletions
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index dcdc1519..b6596327 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -962,6 +962,35 @@ BOOST_AUTO_TEST_CASE(base_constructor_arguments_override) CHECK_SUCCESS(text); } +BOOST_AUTO_TEST_CASE(new_constructor_syntax) +{ + char const* text = R"( + contract A { constructor() public {} } + )"; + CHECK_SUCCESS_NO_WARNINGS(text); +} + +BOOST_AUTO_TEST_CASE(old_constructor_syntax) +{ + char const* text = R"( + contract A { function A() public {} } + )"; + CHECK_WARNING( + text, + "Defining constructors as functions with the same name as the contract is deprecated." + ); + + text = R"( + pragma experimental "v0.5.0"; + contract A { function A() public {} } + )"; + CHECK_ERROR( + text, + SyntaxError, + "Functions are not allowed to have the same name as the contract." + ); +} + BOOST_AUTO_TEST_CASE(implicit_derived_to_base_conversion) { char const* text = R"( @@ -6916,7 +6945,7 @@ BOOST_AUTO_TEST_CASE(shadowing_builtins_ignores_constructor) { char const* text = R"( contract C { - function C() public {} + constructor() public {} } )"; CHECK_SUCCESS_NO_WARNINGS(text); @@ -7328,7 +7357,7 @@ BOOST_AUTO_TEST_CASE(using_this_in_constructor) { char const* text = R"( contract C { - function C() public { + constructor() public { this.f(); } function f() pure public { diff --git a/test/libsolidity/syntaxTests/inheritance/base_arguments_empty_parentheses.sol b/test/libsolidity/syntaxTests/inheritance/base_arguments_empty_parentheses.sol index 76df0657..9607ed60 100644 --- a/test/libsolidity/syntaxTests/inheritance/base_arguments_empty_parentheses.sol +++ b/test/libsolidity/syntaxTests/inheritance/base_arguments_empty_parentheses.sol @@ -1,5 +1,5 @@ contract Base { - function Base(uint) public {} + constructor(uint) public {} } contract Derived is Base(2) { } contract Derived2 is Base(), Derived() { } diff --git a/test/libsolidity/syntaxTests/inheritance/too_few_base_arguments.sol b/test/libsolidity/syntaxTests/inheritance/too_few_base_arguments.sol index 82aba308..45a0770f 100644 --- a/test/libsolidity/syntaxTests/inheritance/too_few_base_arguments.sol +++ b/test/libsolidity/syntaxTests/inheritance/too_few_base_arguments.sol @@ -1,9 +1,9 @@ contract Base { - function Base(uint, uint) public {} + constructor(uint, uint) public {} } contract Derived is Base(2) { } contract Derived2 is Base { - function Derived2() Base(2) public { } + constructor() Base(2) public { } } // ---- // TypeError: Wrong argument count for constructor call: 1 arguments given but expected 2. |