aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-06-20 03:32:03 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-08-01 18:04:35 +0800
commitc8232d9759458d5f6e1442533457d8529686eea7 (patch)
treecb1d8f4876b4984213134ad56ff5fb15db867d57 /test
parent21888e246b771325ea55da39d7f335638da1a98e (diff)
downloaddexon-solidity-c8232d9759458d5f6e1442533457d8529686eea7.tar
dexon-solidity-c8232d9759458d5f6e1442533457d8529686eea7.tar.gz
dexon-solidity-c8232d9759458d5f6e1442533457d8529686eea7.tar.bz2
dexon-solidity-c8232d9759458d5f6e1442533457d8529686eea7.tar.lz
dexon-solidity-c8232d9759458d5f6e1442533457d8529686eea7.tar.xz
dexon-solidity-c8232d9759458d5f6e1442533457d8529686eea7.tar.zst
dexon-solidity-c8232d9759458d5f6e1442533457d8529686eea7.zip
Disallow conversion between unrelated contract types.
Diffstat (limited to 'test')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp6
-rw-r--r--test/libsolidity/syntaxTests/constructor/inconstructible_internal_constructor_inverted.sol5
-rw-r--r--test/libsolidity/syntaxTests/parsing/constructor_allowed_this.sol4
-rw-r--r--test/libsolidity/syntaxTests/types/address_to_contract.sol6
-rw-r--r--test/libsolidity/syntaxTests/types/address_to_contract_implicitly.sol7
-rw-r--r--test/libsolidity/syntaxTests/types/contract_to_address.sol7
-rw-r--r--test/libsolidity/syntaxTests/types/contract_to_address_implicitly.sol8
-rw-r--r--test/libsolidity/syntaxTests/types/contract_to_base.sol9
-rw-r--r--test/libsolidity/syntaxTests/types/contract_to_base_base.sol10
-rw-r--r--test/libsolidity/syntaxTests/types/contract_to_derived.sol9
-rw-r--r--test/libsolidity/syntaxTests/types/contract_to_unrelated_contract.sol9
11 files changed, 72 insertions, 8 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 223250fa..f52d270d 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -9420,7 +9420,7 @@ BOOST_AUTO_TEST_CASE(failed_create)
contract C {
uint public x;
constructor() public payable {}
- function f(uint amount) public returns (address) {
+ function f(uint amount) public returns (D) {
x++;
return (new D).value(amount)();
}
@@ -12524,10 +12524,10 @@ BOOST_AUTO_TEST_CASE(staticcall_for_view_and_pure)
return (new C()).f();
}
function fview() public returns (uint) {
- return (CView(new C())).f();
+ return (CView(address(new C()))).f();
}
function fpure() public returns (uint) {
- return (CPure(new C())).f();
+ return (CPure(address(new C()))).f();
}
}
)";
diff --git a/test/libsolidity/syntaxTests/constructor/inconstructible_internal_constructor_inverted.sol b/test/libsolidity/syntaxTests/constructor/inconstructible_internal_constructor_inverted.sol
index 2a199b3a..ea2ec8f6 100644
--- a/test/libsolidity/syntaxTests/constructor/inconstructible_internal_constructor_inverted.sol
+++ b/test/libsolidity/syntaxTests/constructor/inconstructible_internal_constructor_inverted.sol
@@ -3,11 +3,10 @@
contract B {
A a;
constructor() public {
- a = new A(this);
+ a = new A(address(this));
}
}
contract A {
- constructor(address a) internal {}
+ constructor(address) public {}
}
// ----
-// TypeError: (141-146): Contract with internal constructor cannot be created directly.
diff --git a/test/libsolidity/syntaxTests/parsing/constructor_allowed_this.sol b/test/libsolidity/syntaxTests/parsing/constructor_allowed_this.sol
index 9f714aea..b66253e4 100644
--- a/test/libsolidity/syntaxTests/parsing/constructor_allowed_this.sol
+++ b/test/libsolidity/syntaxTests/parsing/constructor_allowed_this.sol
@@ -3,9 +3,9 @@ contract A {
}
}
contract B {
- constructor(address) public {
+ constructor(C) public {
}
- function b(address) public returns (A) {
+ function b(C) public returns (A) {
return new A();
}
}
diff --git a/test/libsolidity/syntaxTests/types/address_to_contract.sol b/test/libsolidity/syntaxTests/types/address_to_contract.sol
new file mode 100644
index 00000000..629a3df0
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/address_to_contract.sol
@@ -0,0 +1,6 @@
+contract C {
+ function f() public pure returns (C c) {
+ c = C(address(2));
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/types/address_to_contract_implicitly.sol b/test/libsolidity/syntaxTests/types/address_to_contract_implicitly.sol
new file mode 100644
index 00000000..efab7c27
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/address_to_contract_implicitly.sol
@@ -0,0 +1,7 @@
+contract C {
+ function f() public view {
+ C c = address(2);
+ }
+}
+// ----
+// TypeError: (46-62): Type address is not implicitly convertible to expected type contract C.
diff --git a/test/libsolidity/syntaxTests/types/contract_to_address.sol b/test/libsolidity/syntaxTests/types/contract_to_address.sol
new file mode 100644
index 00000000..ec2f8184
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/contract_to_address.sol
@@ -0,0 +1,7 @@
+contract C {
+ function f() public view {
+ address a = address(this);
+ a;
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/types/contract_to_address_implicitly.sol b/test/libsolidity/syntaxTests/types/contract_to_address_implicitly.sol
new file mode 100644
index 00000000..8be9daac
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/contract_to_address_implicitly.sol
@@ -0,0 +1,8 @@
+contract C {
+ function f() public view {
+ address a = this;
+ a;
+ }
+}
+// ----
+// TypeError: (46-62): Type contract C is not implicitly convertible to expected type address.
diff --git a/test/libsolidity/syntaxTests/types/contract_to_base.sol b/test/libsolidity/syntaxTests/types/contract_to_base.sol
new file mode 100644
index 00000000..b0a24e62
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/contract_to_base.sol
@@ -0,0 +1,9 @@
+contract A {}
+contract B is A {}
+contract C {
+ function f() public {
+ A a = new B();
+ a;
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/types/contract_to_base_base.sol b/test/libsolidity/syntaxTests/types/contract_to_base_base.sol
new file mode 100644
index 00000000..e99e5cdc
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/contract_to_base_base.sol
@@ -0,0 +1,10 @@
+contract A {}
+contract B is A {}
+contract C is B {}
+contract D {
+ function f() public {
+ A a = new C();
+ a;
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/types/contract_to_derived.sol b/test/libsolidity/syntaxTests/types/contract_to_derived.sol
new file mode 100644
index 00000000..ac8df5d1
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/contract_to_derived.sol
@@ -0,0 +1,9 @@
+contract B {}
+contract A is B {}
+contract C {
+ function f() public pure {
+ A a = A(new B());
+ }
+}
+// ----
+// TypeError: (85-95): Explicit type conversion not allowed from "contract B" to "contract A".
diff --git a/test/libsolidity/syntaxTests/types/contract_to_unrelated_contract.sol b/test/libsolidity/syntaxTests/types/contract_to_unrelated_contract.sol
new file mode 100644
index 00000000..b0a4875f
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/contract_to_unrelated_contract.sol
@@ -0,0 +1,9 @@
+contract A {}
+contract B {}
+contract C {
+ function f() public pure {
+ B b = B(new A());
+ }
+}
+// ----
+// TypeError: (80-90): Explicit type conversion not allowed from "contract A" to "contract B".