mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Disallow conversion between unrelated contract types.
This commit is contained in:
committed by
Alex Beregszaszi
parent
21888e246b
commit
c8232d9759
+2
-3
@@ -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.
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
contract C {
|
||||
function f() public pure returns (C c) {
|
||||
c = C(address(2));
|
||||
}
|
||||
}
|
||||
// ----
|
||||
@@ -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.
|
||||
@@ -0,0 +1,7 @@
|
||||
contract C {
|
||||
function f() public view {
|
||||
address a = address(this);
|
||||
a;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
@@ -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.
|
||||
@@ -0,0 +1,9 @@
|
||||
contract A {}
|
||||
contract B is A {}
|
||||
contract C {
|
||||
function f() public {
|
||||
A a = new B();
|
||||
a;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,10 @@
|
||||
contract A {}
|
||||
contract B is A {}
|
||||
contract C is B {}
|
||||
contract D {
|
||||
function f() public {
|
||||
A a = new C();
|
||||
a;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
@@ -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".
|
||||
@@ -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".
|
||||
Reference in New Issue
Block a user