aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity/syntaxTests
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-04-17 17:39:40 +0800
committerchriseth <chris@ethereum.org>2018-04-18 20:24:35 +0800
commitf510348ff1d9f0839a4257d6e05f59304247b4e7 (patch)
treeec495e021acd71125c28b0b4f7dfb1963ae32542 /test/libsolidity/syntaxTests
parentf92574705033595b4a6bc20473c9f58e6f184f47 (diff)
downloaddexon-solidity-f510348ff1d9f0839a4257d6e05f59304247b4e7.tar
dexon-solidity-f510348ff1d9f0839a4257d6e05f59304247b4e7.tar.gz
dexon-solidity-f510348ff1d9f0839a4257d6e05f59304247b4e7.tar.bz2
dexon-solidity-f510348ff1d9f0839a4257d6e05f59304247b4e7.tar.lz
dexon-solidity-f510348ff1d9f0839a4257d6e05f59304247b4e7.tar.xz
dexon-solidity-f510348ff1d9f0839a4257d6e05f59304247b4e7.tar.zst
dexon-solidity-f510348ff1d9f0839a4257d6e05f59304247b4e7.zip
Extract tests.
Diffstat (limited to 'test/libsolidity/syntaxTests')
-rw-r--r--test/libsolidity/syntaxTests/constructor/constructible_internal_constructor_new.sol6
-rw-r--r--test/libsolidity/syntaxTests/constructor/constructible_internal_constructor_old.sol9
-rw-r--r--test/libsolidity/syntaxTests/constructor/constructor_new.sol1
-rw-r--r--test/libsolidity/syntaxTests/constructor/constructor_old.sol3
-rw-r--r--test/libsolidity/syntaxTests/constructor/constructor_old_050.sol4
-rw-r--r--test/libsolidity/syntaxTests/constructor/constructor_state_mutability_new.sol13
-rw-r--r--test/libsolidity/syntaxTests/constructor/constructor_state_mutability_old.sol16
-rw-r--r--test/libsolidity/syntaxTests/constructor/constructor_visibility_new.sol12
-rw-r--r--test/libsolidity/syntaxTests/constructor/constructor_visibility_old.sol13
-rw-r--r--test/libsolidity/syntaxTests/constructor/constructor_without_implementation_new.sol5
-rw-r--r--test/libsolidity/syntaxTests/constructor/constructor_without_implementation_old.sol6
-rw-r--r--test/libsolidity/syntaxTests/constructor/external_constructor_new.sol5
-rw-r--r--test/libsolidity/syntaxTests/constructor/external_constructor_old.sol6
-rw-r--r--test/libsolidity/syntaxTests/constructor/inconstructible_internal_constructor_inverted_new.sol13
-rw-r--r--test/libsolidity/syntaxTests/constructor/inconstructible_internal_constructor_inverted_old.sol15
-rw-r--r--test/libsolidity/syntaxTests/constructor/inconstructible_internal_constructor_new.sol8
-rw-r--r--test/libsolidity/syntaxTests/constructor/inconstructible_internal_constructor_old.sol9
-rw-r--r--test/libsolidity/syntaxTests/constructor/interface_constructor_new.sol7
-rw-r--r--test/libsolidity/syntaxTests/constructor/interface_constructor_old.sol8
-rw-r--r--test/libsolidity/syntaxTests/constructor/library_constructor_new.sol6
-rw-r--r--test/libsolidity/syntaxTests/constructor/library_constructor_old.sol7
-rw-r--r--test/libsolidity/syntaxTests/constructor/overriding_constructor.sol6
-rw-r--r--test/libsolidity/syntaxTests/constructor/returns_in_constructor_new.sol5
-rw-r--r--test/libsolidity/syntaxTests/constructor/returns_in_constructor_old.sol6
-rw-r--r--test/libsolidity/syntaxTests/constructor/two_constructors_old.sol8
25 files changed, 197 insertions, 0 deletions
diff --git a/test/libsolidity/syntaxTests/constructor/constructible_internal_constructor_new.sol b/test/libsolidity/syntaxTests/constructor/constructible_internal_constructor_new.sol
new file mode 100644
index 00000000..8dee4c71
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constructor/constructible_internal_constructor_new.sol
@@ -0,0 +1,6 @@
+contract C {
+ constructor() internal {}
+}
+contract D is C {
+ constructor() public { }
+}
diff --git a/test/libsolidity/syntaxTests/constructor/constructible_internal_constructor_old.sol b/test/libsolidity/syntaxTests/constructor/constructible_internal_constructor_old.sol
new file mode 100644
index 00000000..144743e3
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constructor/constructible_internal_constructor_old.sol
@@ -0,0 +1,9 @@
+contract C {
+ function C() internal {}
+}
+contract D is C {
+ function D() public {}
+}
+// ----
+// Warning: (14-38): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
+// Warning: (60-82): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
diff --git a/test/libsolidity/syntaxTests/constructor/constructor_new.sol b/test/libsolidity/syntaxTests/constructor/constructor_new.sol
new file mode 100644
index 00000000..aa3422cc
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constructor/constructor_new.sol
@@ -0,0 +1 @@
+contract A { constructor() public {} }
diff --git a/test/libsolidity/syntaxTests/constructor/constructor_old.sol b/test/libsolidity/syntaxTests/constructor/constructor_old.sol
new file mode 100644
index 00000000..9ec6257d
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constructor/constructor_old.sol
@@ -0,0 +1,3 @@
+contract A { function A() public {} }
+// ----
+// Warning: (13-35): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
diff --git a/test/libsolidity/syntaxTests/constructor/constructor_old_050.sol b/test/libsolidity/syntaxTests/constructor/constructor_old_050.sol
new file mode 100644
index 00000000..19e46e79
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constructor/constructor_old_050.sol
@@ -0,0 +1,4 @@
+pragma experimental "v0.5.0";
+contract A { function A() public {} }
+// ----
+// SyntaxError: (43-65): Functions are not allowed to have the same name as the contract. If you intend this to be a constructor, use "constructor(...) { ... }" to define it.
diff --git a/test/libsolidity/syntaxTests/constructor/constructor_state_mutability_new.sol b/test/libsolidity/syntaxTests/constructor/constructor_state_mutability_new.sol
new file mode 100644
index 00000000..15ed0e1e
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constructor/constructor_state_mutability_new.sol
@@ -0,0 +1,13 @@
+contract test1 {
+ constructor() constant {}
+}
+contract test2 {
+ constructor() view {}
+}
+contract test3 {
+ constructor() pure {}
+}
+// ----
+// TypeError: (19-44): Constructor must be payable or non-payable, but is "view".
+// TypeError: (66-87): Constructor must be payable or non-payable, but is "view".
+// TypeError: (109-130): Constructor must be payable or non-payable, but is "pure".
diff --git a/test/libsolidity/syntaxTests/constructor/constructor_state_mutability_old.sol b/test/libsolidity/syntaxTests/constructor/constructor_state_mutability_old.sol
new file mode 100644
index 00000000..6dbcbc97
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constructor/constructor_state_mutability_old.sol
@@ -0,0 +1,16 @@
+contract test1 {
+ function test1() constant {}
+}
+contract test2 {
+ function test2() view {}
+}
+contract test3 {
+ function test3() pure {}
+}
+// ----
+// Warning: (21-49): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
+// Warning: (73-97): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
+// Warning: (121-145): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
+// TypeError: (21-49): Constructor must be payable or non-payable, but is "view".
+// TypeError: (73-97): Constructor must be payable or non-payable, but is "view".
+// TypeError: (121-145): Constructor must be payable or non-payable, but is "pure".
diff --git a/test/libsolidity/syntaxTests/constructor/constructor_visibility_new.sol b/test/libsolidity/syntaxTests/constructor/constructor_visibility_new.sol
new file mode 100644
index 00000000..502dc029
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constructor/constructor_visibility_new.sol
@@ -0,0 +1,12 @@
+// The constructor of a base class should not be visible in the derived class
+contract A { constructor(string) public { } }
+contract B is A {
+ function f() pure public {
+ A x = A(0); // convert from address
+ string memory y = "ab";
+ A(y); // call as a function is invalid
+ x;
+ }
+}
+// ----
+// TypeError: (243-247): Explicit type conversion not allowed from "string memory" to "contract A".
diff --git a/test/libsolidity/syntaxTests/constructor/constructor_visibility_old.sol b/test/libsolidity/syntaxTests/constructor/constructor_visibility_old.sol
new file mode 100644
index 00000000..847ea27b
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constructor/constructor_visibility_old.sol
@@ -0,0 +1,13 @@
+// The constructor of a base class should not be visible in the derived class
+contract A { function A(string s) public { } }
+contract B is A {
+ function f() pure public {
+ A x = A(0); // convert from address
+ string memory y = "ab";
+ A(y); // call as a function is invalid
+ x;
+ }
+}
+// ----
+// Warning: (91-122): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
+// TypeError: (244-248): Explicit type conversion not allowed from "string memory" to "contract A".
diff --git a/test/libsolidity/syntaxTests/constructor/constructor_without_implementation_new.sol b/test/libsolidity/syntaxTests/constructor/constructor_without_implementation_new.sol
new file mode 100644
index 00000000..5e619143
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constructor/constructor_without_implementation_new.sol
@@ -0,0 +1,5 @@
+contract C {
+ constructor();
+}
+// ----
+// TypeError: (14-28): Constructor must be implemented if declared.
diff --git a/test/libsolidity/syntaxTests/constructor/constructor_without_implementation_old.sol b/test/libsolidity/syntaxTests/constructor/constructor_without_implementation_old.sol
new file mode 100644
index 00000000..72458703
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constructor/constructor_without_implementation_old.sol
@@ -0,0 +1,6 @@
+contract C {
+ function C();
+}
+// ----
+// Warning: (14-27): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
+// TypeError: (14-27): Constructor must be implemented if declared.
diff --git a/test/libsolidity/syntaxTests/constructor/external_constructor_new.sol b/test/libsolidity/syntaxTests/constructor/external_constructor_new.sol
new file mode 100644
index 00000000..30cf0668
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constructor/external_constructor_new.sol
@@ -0,0 +1,5 @@
+contract test {
+ constructor() external {}
+}
+// ----
+// TypeError: (17-42): Constructor must be public or internal.
diff --git a/test/libsolidity/syntaxTests/constructor/external_constructor_old.sol b/test/libsolidity/syntaxTests/constructor/external_constructor_old.sol
new file mode 100644
index 00000000..27869361
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constructor/external_constructor_old.sol
@@ -0,0 +1,6 @@
+contract test {
+ function test() external {}
+}
+// ----
+// Warning: (17-44): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
+// TypeError: (17-44): Constructor must be public or internal.
diff --git a/test/libsolidity/syntaxTests/constructor/inconstructible_internal_constructor_inverted_new.sol b/test/libsolidity/syntaxTests/constructor/inconstructible_internal_constructor_inverted_new.sol
new file mode 100644
index 00000000..2a199b3a
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constructor/inconstructible_internal_constructor_inverted_new.sol
@@ -0,0 +1,13 @@
+// Previously, the type information for A was not yet available at the point of
+// "new A".
+contract B {
+ A a;
+ constructor() public {
+ a = new A(this);
+ }
+}
+contract A {
+ constructor(address a) internal {}
+}
+// ----
+// TypeError: (141-146): Contract with internal constructor cannot be created directly.
diff --git a/test/libsolidity/syntaxTests/constructor/inconstructible_internal_constructor_inverted_old.sol b/test/libsolidity/syntaxTests/constructor/inconstructible_internal_constructor_inverted_old.sol
new file mode 100644
index 00000000..0a27e9f8
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constructor/inconstructible_internal_constructor_inverted_old.sol
@@ -0,0 +1,15 @@
+// Previously, the type information for A was not yet available at the point of
+// "new A".
+contract B {
+ A a;
+ function B() public {
+ a = new A(this);
+ }
+}
+contract A {
+ function A(address a) internal {}
+}
+// ----
+// Warning: (112-155): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
+// Warning: (172-205): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
+// TypeError: (140-145): Contract with internal constructor cannot be created directly.
diff --git a/test/libsolidity/syntaxTests/constructor/inconstructible_internal_constructor_new.sol b/test/libsolidity/syntaxTests/constructor/inconstructible_internal_constructor_new.sol
new file mode 100644
index 00000000..2511c751
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constructor/inconstructible_internal_constructor_new.sol
@@ -0,0 +1,8 @@
+contract C {
+ constructor() internal {}
+}
+contract D {
+ function f() public { C c = new C(); c; }
+}
+// ----
+// TypeError: (84-89): Contract with internal constructor cannot be created directly.
diff --git a/test/libsolidity/syntaxTests/constructor/inconstructible_internal_constructor_old.sol b/test/libsolidity/syntaxTests/constructor/inconstructible_internal_constructor_old.sol
new file mode 100644
index 00000000..2897e6f3
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constructor/inconstructible_internal_constructor_old.sol
@@ -0,0 +1,9 @@
+contract C {
+ function C() internal {}
+}
+contract D {
+ function f() public { C x = new C(); x; }
+}
+// ----
+// Warning: (14-38): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
+// TypeError: (83-88): Contract with internal constructor cannot be created directly.
diff --git a/test/libsolidity/syntaxTests/constructor/interface_constructor_new.sol b/test/libsolidity/syntaxTests/constructor/interface_constructor_new.sol
new file mode 100644
index 00000000..fa5d54c4
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constructor/interface_constructor_new.sol
@@ -0,0 +1,7 @@
+interface I {
+ constructor();
+}
+// ----
+// Warning: (15-29): Functions in interfaces should be declared external.
+// TypeError: (15-29): Constructor cannot be defined in interfaces.
+// TypeError: (15-29): Constructor must be implemented if declared.
diff --git a/test/libsolidity/syntaxTests/constructor/interface_constructor_old.sol b/test/libsolidity/syntaxTests/constructor/interface_constructor_old.sol
new file mode 100644
index 00000000..ddf54977
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constructor/interface_constructor_old.sol
@@ -0,0 +1,8 @@
+interface I {
+ function I();
+}
+// ----
+// Warning: (15-28): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
+// Warning: (15-28): Functions in interfaces should be declared external.
+// TypeError: (15-28): Constructor cannot be defined in interfaces.
+// TypeError: (15-28): Constructor must be implemented if declared.
diff --git a/test/libsolidity/syntaxTests/constructor/library_constructor_new.sol b/test/libsolidity/syntaxTests/constructor/library_constructor_new.sol
new file mode 100644
index 00000000..8db7e62a
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constructor/library_constructor_new.sol
@@ -0,0 +1,6 @@
+library Lib {
+ constructor();
+}
+// ----
+// TypeError: (15-29): Constructor cannot be defined in libraries.
+// TypeError: (15-29): Constructor must be implemented if declared.
diff --git a/test/libsolidity/syntaxTests/constructor/library_constructor_old.sol b/test/libsolidity/syntaxTests/constructor/library_constructor_old.sol
new file mode 100644
index 00000000..d4499049
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constructor/library_constructor_old.sol
@@ -0,0 +1,7 @@
+library Lib {
+ function Lib();
+}
+// ----
+// Warning: (15-30): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
+// TypeError: (15-30): Constructor cannot be defined in libraries.
+// TypeError: (15-30): Constructor must be implemented if declared.
diff --git a/test/libsolidity/syntaxTests/constructor/overriding_constructor.sol b/test/libsolidity/syntaxTests/constructor/overriding_constructor.sol
new file mode 100644
index 00000000..3290a33b
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constructor/overriding_constructor.sol
@@ -0,0 +1,6 @@
+// It is fine to "override" constructor of a base class since it is invisible
+contract A { function A() public { } }
+contract B is A { function A() public pure returns (uint8) {} }
+// ----
+// Warning: (91-114): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
+// Warning: (135-178): This declaration shadows an existing declaration.
diff --git a/test/libsolidity/syntaxTests/constructor/returns_in_constructor_new.sol b/test/libsolidity/syntaxTests/constructor/returns_in_constructor_new.sol
new file mode 100644
index 00000000..e6a03014
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constructor/returns_in_constructor_new.sol
@@ -0,0 +1,5 @@
+contract test {
+ constructor() public returns (uint a) { }
+}
+// ----
+// TypeError: (46-54): Non-empty "returns" directive for constructor.
diff --git a/test/libsolidity/syntaxTests/constructor/returns_in_constructor_old.sol b/test/libsolidity/syntaxTests/constructor/returns_in_constructor_old.sol
new file mode 100644
index 00000000..00b3974c
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constructor/returns_in_constructor_old.sol
@@ -0,0 +1,6 @@
+contract test {
+ function test() public returns (uint a) { }
+}
+// ----
+// Warning: (17-60): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
+// TypeError: (48-56): Non-empty "returns" directive for constructor.
diff --git a/test/libsolidity/syntaxTests/constructor/two_constructors_old.sol b/test/libsolidity/syntaxTests/constructor/two_constructors_old.sol
new file mode 100644
index 00000000..40341c4d
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constructor/two_constructors_old.sol
@@ -0,0 +1,8 @@
+contract test {
+ function test(uint a) public { }
+ function test() public {}
+}
+// ----
+// Warning: (17-49): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
+// Warning: (51-76): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
+// DeclarationError: (17-49): More than one constructor defined.