mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Test updates after disallowing Integer -> Contract conversion
This commit is contained in:
parent
40244c5469
commit
9e5d7b9910
@ -16,7 +16,7 @@ Breaking Changes:
|
||||
* Code Generator: Use ``revert`` with error signature ``Panic(uint256)`` and error codes instead of invalid opcode on failing assertions.
|
||||
* Type System: Explicit conversions from literals to integer type is as strict as implicit conversions.
|
||||
* Type System: Explicit conversions from literals to enums are only allowed if the value fits in the enum.
|
||||
* Type System: Explicit conversions between two types are disallowed if it changes more than one of sign, width or kind.
|
||||
* Type System: Explicit conversions between two types are disallowed if it changes more than one of sign, width or kind at the same time.
|
||||
* Type System: Declarations with the name ``this``, ``super`` and ``_`` are disallowed, with the exception of public functions and events.
|
||||
* Type System: Disallow ``type(super)``.
|
||||
* Command Line Interface: JSON fields `abi`, `devdoc`, `userdoc` and `storage-layout` are now sub-objects rather than strings.
|
||||
|
@ -49,25 +49,27 @@ New Restrictions
|
||||
3. Explicit conversions between literals and enums are only allowed if the literal can
|
||||
represent a value in the enum.
|
||||
|
||||
* There are new restrictions on explicit conversions between two different types. The conversion is
|
||||
only allowed when there is at most one change in sign, width or 'kind' / different type (``int``,
|
||||
``address``, ``bytesNN``, etc.) For example, the conversion ``uint16(int8)`` is disallowed since
|
||||
the conversion changes width (8 bits to 16 bits) and sign (signed integer to unsigned integer.) To
|
||||
get the previous behaviour, use an intermediate conversion. In the previous example, this would be
|
||||
``uint16(uint8(int8))`` or ``uint16(int16(int8))``. The following are some examples of conversions
|
||||
that are disallowed by this rule. Note that, given types ``T`` and ``S``, the notation ``T(S)``
|
||||
refers to the explicit conversion ``T(x)``, where ``x`` is any arbitrary variable of type ``S``.
|
||||
* There are new restrictions on explicit type conversions. The conversion is only allowed when there
|
||||
is at most one change in sign, width or type-category (``int``, ``address``, ``bytesNN``, etc.)
|
||||
|
||||
- ``address(uint)`` and ``uint(address)``: converting both 'kind' and width. Replace this by
|
||||
Let us use the notation ``T(S)`` to denote the explicit conversion ``T(x)``, where, ``T`` and
|
||||
``S`` are types, and ``x`` is any arbitrary variable of type ``S``. An example of such a
|
||||
disallowed conversion would be ``uint16(int8)`` since it changes both width (8 bits to 16 bits)
|
||||
and sign (signed integer to unsigned integer). In order to do the conversion, one has to go
|
||||
through an intermediate type. In the previous example, this would be ``uint16(uint8(int8))`` or
|
||||
``uint16(int16(int8))``. Note that the two ways to convert will produce different results e.g.,
|
||||
for ``-1``. The following are some examples of conversions that are disallowed by this rule.
|
||||
|
||||
- ``address(uint)`` and ``uint(address)``: converting both type-category and width. Replace this by
|
||||
``address(uint160(uint))`` and ``uint(uint160(address))`` respectively.
|
||||
- ``int80(bytes10)`` and ``bytes10(int80)``: converting both 'kind' and sign. Replace this by
|
||||
- ``int80(bytes10)`` and ``bytes10(int80)``: converting both type-category and sign. Replace this by
|
||||
``int80(uint80(bytes10))`` and ``bytes10(uint80(int80)`` respectively.
|
||||
- ``Contract(uint)``: converting 'kind' and width. Replace this by
|
||||
- ``Contract(uint)``: converting both type-category and width. Replace this by
|
||||
``Contract(address(uint160(uint)))``.
|
||||
|
||||
These conversions were disallowed since there was ambiguity in such conversions. For example, in
|
||||
the expression ``uint16 x = uint16(int8(-1))``, the value of ``x`` would depend on whether the sign or
|
||||
the width conversion was applied first.
|
||||
These conversions were disallowed to avoid ambiguity. For example, in the expression ``uint16 x =
|
||||
uint16(int8(-1))``, the value of ``x`` would depend on whether the sign or the width conversion
|
||||
was applied first.
|
||||
|
||||
* Function call options can only be given once, i.e. ``c.f{gas: 10000}{value: 1}()`` is invalid and has to be changed to ``c.f{gas: 10000, value: 1}()``.
|
||||
|
||||
|
@ -784,7 +784,7 @@ Another example that uses external function types::
|
||||
|
||||
|
||||
contract OracleUser {
|
||||
Oracle constant private ORACLE_CONST = Oracle(0x1234567); // known contract
|
||||
Oracle constant private ORACLE_CONST = Oracle(address(0x00000000219ab540356cBB839Cbe05303d7705Fa)); // known contract
|
||||
uint private exchangeRate;
|
||||
|
||||
function buySomething() public {
|
||||
|
@ -471,7 +471,7 @@ BOOST_AUTO_TEST_CASE(structs2)
|
||||
s1[0].t[0].e = E.B;
|
||||
s1[0].t[0].y = 0x12;
|
||||
s2 = new S[](2);
|
||||
s2[1].c = C(0x1234);
|
||||
s2[1].c = C(address(0x1234));
|
||||
s2[1].t = new T[](3);
|
||||
s2[1].t[1].x = 0x21;
|
||||
s2[1].t[1].e = E.C;
|
||||
|
@ -4,7 +4,7 @@ abstract contract D {
|
||||
|
||||
|
||||
contract C {
|
||||
D d = D(0x1212);
|
||||
D d = D(address(0x1212));
|
||||
|
||||
function f() public returns (uint256) {
|
||||
d.g();
|
||||
|
@ -1,7 +1,7 @@
|
||||
contract C {
|
||||
function f() external {}
|
||||
function g() external {
|
||||
C c = C(0x0000000000000000000000000000000000000000000000000000000000000000);
|
||||
C c = C(address(0x0000000000000000000000000000000000000000000000000000000000000000));
|
||||
c.f();
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
contract Test {
|
||||
function test() public returns (uint ret) { return uint(uint160(address(uint160(type(uint200).max)))); }
|
||||
function test() public returns (uint ret) { return uint(uint160(address(uint160(uint128(type(uint200).max))))); }
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// compileToEwasm: also
|
||||
// ----
|
||||
// test() -> 0xffffffffffffffffffffffffffffffffffffffff
|
||||
// test() -> 0xffffffffffffffffffffffffffffffff
|
||||
|
@ -9,9 +9,9 @@ contract C1 {
|
||||
|
||||
contract C {
|
||||
function test() public returns (C1 x, C1 y) {
|
||||
C1 c = new C1(C1(9));
|
||||
C1 c = new C1(C1(address(9)));
|
||||
x = c.bla();
|
||||
y = this.t1(C1(7));
|
||||
y = this.t1(C1(address(7)));
|
||||
}
|
||||
|
||||
function t1(C1 a) public returns (C1) {
|
||||
@ -19,7 +19,7 @@ contract C {
|
||||
}
|
||||
|
||||
function t2() public returns (C1) {
|
||||
return C1(9);
|
||||
return C1(address(9));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,5 +71,3 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 8364: (1468-1469): Assertion checker does not yet implement type type(enum E)
|
||||
// Warning 8364: (1468-1469): Assertion checker does not yet implement type type(enum E)
|
||||
|
@ -67,5 +67,3 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 8364: (1284-1285): Assertion checker does not yet implement type type(contract D)
|
||||
// Warning 8364: (1284-1285): Assertion checker does not yet implement type type(contract D)
|
||||
|
@ -13,8 +13,8 @@ import "A";
|
||||
|
||||
contract Test {
|
||||
function foo() public view {
|
||||
C(0x00).set({_item: C.Item(50), _z: false, _y: "abc", _x: 30});
|
||||
C(address(0x00)).set({_item: C.Item(50), _z: false, _y: "abc", _x: 30});
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 2443: (B:90-100): The type of this parameter, struct C.Item, is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
|
||||
// TypeError 2443: (B:99-109): The type of this parameter, struct C.Item, is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
|
||||
|
@ -9,8 +9,8 @@ import "A";
|
||||
|
||||
contract D {
|
||||
function g() public view {
|
||||
C(0x00).f();
|
||||
C(address(0x00)).f();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 2428: (B:65-76): The type of return parameter 1, string[], is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
|
||||
// TypeError 2428: (B:65-85): The type of return parameter 1, string[], is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
|
||||
|
@ -13,8 +13,8 @@ import "A";
|
||||
|
||||
contract Test {
|
||||
function foo() public view {
|
||||
C(0x00).get();
|
||||
C(address(0x00)).get();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 2428: (B:70-83): The type of return parameter 1, struct C.Item, is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
|
||||
// TypeError 2428: (B:70-92): The type of return parameter 1, struct C.Item, is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
|
||||
|
@ -13,8 +13,8 @@ import "A";
|
||||
|
||||
contract Test {
|
||||
function foo() public view {
|
||||
C(0x00).get();
|
||||
C(address(0x00)).get();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 2428: (B:70-83): The type of return parameter 1, struct C.Item, is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
|
||||
// TypeError 2428: (B:70-92): The type of return parameter 1, struct C.Item, is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
|
||||
|
@ -11,7 +11,7 @@ contract A {
|
||||
|
||||
contract B {
|
||||
modifier validate() {
|
||||
A(0x00).get();
|
||||
A(address(0x00)).get();
|
||||
_;
|
||||
}
|
||||
}
|
||||
|
@ -11,11 +11,11 @@ contract A {
|
||||
|
||||
contract B {
|
||||
constructor() validate {
|
||||
A(0x00).get();
|
||||
A(address(0x00)).get();
|
||||
}
|
||||
|
||||
modifier validate() {
|
||||
A(0x00).get();
|
||||
A(address(0x00)).get();
|
||||
_;
|
||||
}
|
||||
}
|
||||
|
@ -11,11 +11,11 @@ contract A {
|
||||
|
||||
contract B {
|
||||
constructor() {
|
||||
A(0x00).get();
|
||||
A(address(0x00)).get();
|
||||
}
|
||||
|
||||
function foo() public view {
|
||||
A(0x00).get();
|
||||
A(address(0x00)).get();
|
||||
}
|
||||
}
|
||||
==== Source: B ====
|
||||
|
@ -11,7 +11,7 @@ contract A {
|
||||
|
||||
contract B {
|
||||
modifier validate() virtual {
|
||||
A(0x00).get();
|
||||
A(address(0x00)).get();
|
||||
_;
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ import "X";
|
||||
|
||||
contract V2A {
|
||||
modifier modV2A() {
|
||||
X(0x00).get();
|
||||
X(address(0x00)).get();
|
||||
_;
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import "A";
|
||||
|
||||
contract D {
|
||||
function g() public view {
|
||||
C(0x00).f();
|
||||
C(address(0x00)).f();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
|
@ -15,7 +15,7 @@ import "A";
|
||||
|
||||
contract Test {
|
||||
function foo() public view {
|
||||
C(0x00).get();
|
||||
C(address(0x00)).get();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
|
@ -15,7 +15,7 @@ import "A";
|
||||
|
||||
contract Test {
|
||||
function foo() public view {
|
||||
C(0x00).get();
|
||||
C(address(0x00)).get();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
|
@ -13,7 +13,7 @@ import "A";
|
||||
|
||||
contract B {
|
||||
modifier validate() {
|
||||
A(0x00).get();
|
||||
A(address(0x00)).get();
|
||||
_;
|
||||
}
|
||||
}
|
||||
@ -27,4 +27,4 @@ contract C is B {
|
||||
{}
|
||||
}
|
||||
// ----
|
||||
// TypeError 2428: (B:60-73): The type of return parameter 1, struct Data, is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
|
||||
// TypeError 2428: (B:60-82): The type of return parameter 1, struct Data, is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
|
||||
|
@ -13,7 +13,7 @@ import "A";
|
||||
|
||||
contract B {
|
||||
modifier validate() {
|
||||
A(0x00).get();
|
||||
A(address(0x00)).get();
|
||||
_;
|
||||
}
|
||||
}
|
||||
@ -29,4 +29,4 @@ contract C is B {
|
||||
{}
|
||||
}
|
||||
// ----
|
||||
// TypeError 2428: (B:60-73): The type of return parameter 1, struct Data, is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
|
||||
// TypeError 2428: (B:60-82): The type of return parameter 1, struct Data, is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
|
||||
|
@ -2,12 +2,12 @@
|
||||
contract A { constructor(string memory) { } }
|
||||
contract B is A {
|
||||
function f() pure public {
|
||||
A x = A(0); // convert from address
|
||||
A x = A(address(0)); // convert from address
|
||||
string memory y = "ab";
|
||||
A(y); // call as a function is invalid
|
||||
x;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 3656: (124-294): Contract "B" should be marked as abstract.
|
||||
// TypeError 9640: (243-247): Explicit type conversion not allowed from "string memory" to "contract A".
|
||||
// TypeError 3656: (124-303): Contract "B" should be marked as abstract.
|
||||
// TypeError 9640: (252-256): Explicit type conversion not allowed from "string memory" to "contract A".
|
||||
|
@ -1,4 +1,4 @@
|
||||
==== Source: a ====
|
||||
contract A {}
|
||||
==== Source: dir/a/b/c ====
|
||||
import "../../.././a" as x; contract B is x.A { fallback() external { x.A r = x.A(20); r; } }
|
||||
import "../../.././a" as x; contract B is x.A { fallback() external { x.A r = x.A(address(20)); r; } }
|
||||
|
@ -1,12 +1,12 @@
|
||||
contract First {
|
||||
function fun() public returns (bool) {
|
||||
return Second(1).fun(1, true, 3) > 0;
|
||||
return Second(address(1)).fun(1, true, 3) > 0;
|
||||
}
|
||||
}
|
||||
contract Second {
|
||||
function fun(uint, bool, uint) public returns (uint) {
|
||||
if (First(2).fun() == true) return 1;
|
||||
if (First(address(2)).fun() == true) return 1;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 6321: (183-187): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable.
|
||||
// Warning 6321: (192-196): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable.
|
||||
|
@ -1,4 +1,4 @@
|
||||
contract A { function f() public virtual { uint8 x = C(0).g(); } }
|
||||
contract A { function f() public virtual { uint8 x = C(address(0)).g(); } }
|
||||
contract B { function f() public virtual {} function g() public returns (uint8) {} }
|
||||
contract C is A, B { function f() public override (A, B) { A.f(); } }
|
||||
// ----
|
||||
|
@ -1,7 +1,7 @@
|
||||
contract A { }
|
||||
contract B is A {
|
||||
function f() public { A a = B(1); }
|
||||
function f() public { A a = B(address(1)); }
|
||||
}
|
||||
// ----
|
||||
// Warning 2072: (59-62): Unused local variable.
|
||||
// Warning 2018: (37-72): Function state mutability can be restricted to pure
|
||||
// Warning 2018: (37-81): Function state mutability can be restricted to pure
|
||||
|
@ -1,6 +1,6 @@
|
||||
contract A { }
|
||||
contract B is A {
|
||||
function f() public { B b = A(1); }
|
||||
function f() public { B b = A(address(1)); }
|
||||
}
|
||||
// ----
|
||||
// TypeError 9574: (59-69): Type contract A is not implicitly convertible to expected type contract B.
|
||||
// TypeError 9574: (59-78): Type contract A is not implicitly convertible to expected type contract B.
|
||||
|
@ -2,6 +2,6 @@ contract c {
|
||||
function f() public {}
|
||||
}
|
||||
contract d {
|
||||
function g() public { c(0).f(); }
|
||||
function g() public { c(address(0)).f(); }
|
||||
}
|
||||
// ----
|
||||
|
@ -2,7 +2,7 @@ contract c {
|
||||
function f() internal {}
|
||||
}
|
||||
contract d {
|
||||
function g() public { c(0).f(); }
|
||||
function g() public { c(address(0)).f(); }
|
||||
}
|
||||
// ----
|
||||
// TypeError 9582: (83-89): Member "f" not found or not visible after argument-dependent lookup in contract c.
|
||||
// TypeError 9582: (83-98): Member "f" not found or not visible after argument-dependent lookup in contract c.
|
||||
|
@ -2,7 +2,7 @@ contract c {
|
||||
uint a;
|
||||
}
|
||||
contract d {
|
||||
function g() public { c(0).a(); }
|
||||
function g() public { c(address(0)).a(); }
|
||||
}
|
||||
// ----
|
||||
// TypeError 9582: (66-72): Member "a" not found or not visible after argument-dependent lookup in contract c.
|
||||
// TypeError 9582: (66-81): Member "a" not found or not visible after argument-dependent lookup in contract c.
|
||||
|
@ -2,7 +2,7 @@ contract c {
|
||||
uint public a;
|
||||
}
|
||||
contract d {
|
||||
function g() public { c(0).a(); }
|
||||
function g() public { c(address(0)).a(); }
|
||||
}
|
||||
// ----
|
||||
// Warning 2018: (51-84): Function state mutability can be restricted to view
|
||||
// Warning 2018: (51-93): Function state mutability can be restricted to view
|
||||
|
@ -1,3 +1,3 @@
|
||||
contract C {
|
||||
C constant x = C(0x123);
|
||||
C constant x = C(address(0x123));
|
||||
}
|
||||
|
@ -256,7 +256,7 @@ contract Main {
|
||||
A constant JU = JV;
|
||||
A constant JV = JW;
|
||||
A constant JW = JX;
|
||||
A constant JX = A(0x00);
|
||||
A constant JX = A(address(0x00));
|
||||
}
|
||||
// ----
|
||||
// DeclarationError 7380: (6105-6123): Variable definition exhausting cyclic dependency validator.
|
||||
|
@ -131,5 +131,5 @@ contract Main {
|
||||
A constant EZ = FA;
|
||||
A constant FA = FB;
|
||||
A constant FB = FC;
|
||||
A constant FC = A(0x00);
|
||||
A constant FC = A(address(0x00));
|
||||
}
|
||||
|
@ -4,39 +4,39 @@ contract C
|
||||
function f() public pure {
|
||||
|
||||
uint16 a = uint16(uint8(int8(-1)));
|
||||
a;
|
||||
a;
|
||||
|
||||
int8 b = -1;
|
||||
b;
|
||||
b;
|
||||
uint16 c = uint16(uint8(b));
|
||||
c;
|
||||
c;
|
||||
|
||||
int8 d = int8(int16(uint16(type(uint16).max)));
|
||||
d;
|
||||
d;
|
||||
|
||||
uint16 e = type(uint16).max;
|
||||
e;
|
||||
e;
|
||||
int8 g = int8(uint8(e));
|
||||
g;
|
||||
g;
|
||||
|
||||
address h = address(uint160(uint(type(uint).max)));
|
||||
h;
|
||||
h;
|
||||
|
||||
uint i = uint(uint160(address(0)));
|
||||
i;
|
||||
i;
|
||||
|
||||
uint j = type(uint).max;
|
||||
j;
|
||||
j;
|
||||
address k = address(uint160(j));
|
||||
k;
|
||||
k;
|
||||
|
||||
int80 l = int80(uint80(bytes10("h")));
|
||||
l;
|
||||
l;
|
||||
bytes10 m = bytes10(uint80(int80(-1)));
|
||||
m;
|
||||
m;
|
||||
|
||||
B n = B(uint(int(100)));
|
||||
n;
|
||||
B n = B(address(uint160(uint(int(100)))));
|
||||
n;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
|
@ -3,7 +3,7 @@ contract C {
|
||||
return this;
|
||||
}
|
||||
function g() pure public returns (bytes4) {
|
||||
C x = C(0x123);
|
||||
C x = C(address(0x123));
|
||||
return x.f.selector;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user