Test updates after disallowing Integer -> Contract conversion

This commit is contained in:
hrkrshnn 2020-11-10 14:14:43 +01:00
parent 40244c5469
commit 9e5d7b9910
39 changed files with 85 additions and 87 deletions

View File

@ -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. * 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 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 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: Declarations with the name ``this``, ``super`` and ``_`` are disallowed, with the exception of public functions and events.
* Type System: Disallow ``type(super)``. * Type System: Disallow ``type(super)``.
* Command Line Interface: JSON fields `abi`, `devdoc`, `userdoc` and `storage-layout` are now sub-objects rather than strings. * Command Line Interface: JSON fields `abi`, `devdoc`, `userdoc` and `storage-layout` are now sub-objects rather than strings.

View File

@ -49,25 +49,27 @@ New Restrictions
3. Explicit conversions between literals and enums are only allowed if the literal can 3. Explicit conversions between literals and enums are only allowed if the literal can
represent a value in the enum. represent a value in the enum.
* There are new restrictions on explicit conversions between two different types. The conversion is * There are new restrictions on explicit type conversions. The conversion is only allowed when there
only allowed when there is at most one change in sign, width or 'kind' / different type (``int``, is at most one change in sign, width or type-category (``int``, ``address``, ``bytesNN``, etc.)
``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``.
- ``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. ``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. ``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)))``. ``Contract(address(uint160(uint)))``.
These conversions were disallowed since there was ambiguity in such conversions. For example, in These conversions were disallowed to avoid ambiguity. For example, in the expression ``uint16 x =
the expression ``uint16 x = uint16(int8(-1))``, the value of ``x`` would depend on whether the sign or uint16(int8(-1))``, the value of ``x`` would depend on whether the sign or the width conversion
the width conversion was applied first. 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}()``. * 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}()``.

View File

@ -784,7 +784,7 @@ Another example that uses external function types::
contract OracleUser { contract OracleUser {
Oracle constant private ORACLE_CONST = Oracle(0x1234567); // known contract Oracle constant private ORACLE_CONST = Oracle(address(0x00000000219ab540356cBB839Cbe05303d7705Fa)); // known contract
uint private exchangeRate; uint private exchangeRate;
function buySomething() public { function buySomething() public {

View File

@ -471,7 +471,7 @@ BOOST_AUTO_TEST_CASE(structs2)
s1[0].t[0].e = E.B; s1[0].t[0].e = E.B;
s1[0].t[0].y = 0x12; s1[0].t[0].y = 0x12;
s2 = new S[](2); s2 = new S[](2);
s2[1].c = C(0x1234); s2[1].c = C(address(0x1234));
s2[1].t = new T[](3); s2[1].t = new T[](3);
s2[1].t[1].x = 0x21; s2[1].t[1].x = 0x21;
s2[1].t[1].e = E.C; s2[1].t[1].e = E.C;

View File

@ -4,7 +4,7 @@ abstract contract D {
contract C { contract C {
D d = D(0x1212); D d = D(address(0x1212));
function f() public returns (uint256) { function f() public returns (uint256) {
d.g(); d.g();

View File

@ -1,7 +1,7 @@
contract C { contract C {
function f() external {} function f() external {}
function g() external { function g() external {
C c = C(0x0000000000000000000000000000000000000000000000000000000000000000); C c = C(address(0x0000000000000000000000000000000000000000000000000000000000000000));
c.f(); c.f();
} }
} }

View File

@ -1,8 +1,8 @@
contract Test { 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 // compileViaYul: also
// compileToEwasm: also // compileToEwasm: also
// ---- // ----
// test() -> 0xffffffffffffffffffffffffffffffffffffffff // test() -> 0xffffffffffffffffffffffffffffffff

View File

@ -9,9 +9,9 @@ contract C1 {
contract C { contract C {
function test() public returns (C1 x, C1 y) { function test() public returns (C1 x, C1 y) {
C1 c = new C1(C1(9)); C1 c = new C1(C1(address(9)));
x = c.bla(); x = c.bla();
y = this.t1(C1(7)); y = this.t1(C1(address(7)));
} }
function t1(C1 a) public returns (C1) { function t1(C1 a) public returns (C1) {
@ -19,7 +19,7 @@ contract C {
} }
function t2() public returns (C1) { function t2() public returns (C1) {
return C1(9); return C1(address(9));
} }
} }

View File

@ -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)

View File

@ -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)

View File

@ -13,8 +13,8 @@ import "A";
contract Test { contract Test {
function foo() public view { 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.

View File

@ -9,8 +9,8 @@ import "A";
contract D { contract D {
function g() public view { 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.

View File

@ -13,8 +13,8 @@ import "A";
contract Test { contract Test {
function foo() public view { 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.

View File

@ -13,8 +13,8 @@ import "A";
contract Test { contract Test {
function foo() public view { 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.

View File

@ -11,7 +11,7 @@ contract A {
contract B { contract B {
modifier validate() { modifier validate() {
A(0x00).get(); A(address(0x00)).get();
_; _;
} }
} }

View File

@ -11,11 +11,11 @@ contract A {
contract B { contract B {
constructor() validate { constructor() validate {
A(0x00).get(); A(address(0x00)).get();
} }
modifier validate() { modifier validate() {
A(0x00).get(); A(address(0x00)).get();
_; _;
} }
} }

View File

@ -11,11 +11,11 @@ contract A {
contract B { contract B {
constructor() { constructor() {
A(0x00).get(); A(address(0x00)).get();
} }
function foo() public view { function foo() public view {
A(0x00).get(); A(address(0x00)).get();
} }
} }
==== Source: B ==== ==== Source: B ====

View File

@ -11,7 +11,7 @@ contract A {
contract B { contract B {
modifier validate() virtual { modifier validate() virtual {
A(0x00).get(); A(address(0x00)).get();
_; _;
} }
} }

View File

@ -35,7 +35,7 @@ import "X";
contract V2A { contract V2A {
modifier modV2A() { modifier modV2A() {
X(0x00).get(); X(address(0x00)).get();
_; _;
} }
} }

View File

@ -11,7 +11,7 @@ import "A";
contract D { contract D {
function g() public view { function g() public view {
C(0x00).f(); C(address(0x00)).f();
} }
} }
// ---- // ----

View File

@ -15,7 +15,7 @@ import "A";
contract Test { contract Test {
function foo() public view { function foo() public view {
C(0x00).get(); C(address(0x00)).get();
} }
} }
// ---- // ----

View File

@ -15,7 +15,7 @@ import "A";
contract Test { contract Test {
function foo() public view { function foo() public view {
C(0x00).get(); C(address(0x00)).get();
} }
} }
// ---- // ----

View File

@ -13,7 +13,7 @@ import "A";
contract B { contract B {
modifier validate() { 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.

View File

@ -13,7 +13,7 @@ import "A";
contract B { contract B {
modifier validate() { 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.

View File

@ -2,12 +2,12 @@
contract A { constructor(string memory) { } } contract A { constructor(string memory) { } }
contract B is A { contract B is A {
function f() pure public { function f() pure public {
A x = A(0); // convert from address A x = A(address(0)); // convert from address
string memory y = "ab"; string memory y = "ab";
A(y); // call as a function is invalid A(y); // call as a function is invalid
x; x;
} }
} }
// ---- // ----
// TypeError 3656: (124-294): Contract "B" should be marked as abstract. // TypeError 3656: (124-303): Contract "B" should be marked as abstract.
// TypeError 9640: (243-247): Explicit type conversion not allowed from "string memory" to "contract A". // TypeError 9640: (252-256): Explicit type conversion not allowed from "string memory" to "contract A".

View File

@ -1,4 +1,4 @@
==== Source: a ==== ==== Source: a ====
contract A {} contract A {}
==== Source: dir/a/b/c ==== ==== 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; } }

View File

@ -1,12 +1,12 @@
contract First { contract First {
function fun() public returns (bool) { function fun() public returns (bool) {
return Second(1).fun(1, true, 3) > 0; return Second(address(1)).fun(1, true, 3) > 0;
} }
} }
contract Second { contract Second {
function fun(uint, bool, uint) public returns (uint) { 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.

View File

@ -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 B { function f() public virtual {} function g() public returns (uint8) {} }
contract C is A, B { function f() public override (A, B) { A.f(); } } contract C is A, B { function f() public override (A, B) { A.f(); } }
// ---- // ----

View File

@ -1,7 +1,7 @@
contract A { } contract A { }
contract B is 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 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

View File

@ -1,6 +1,6 @@
contract A { } contract A { }
contract B is 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.

View File

@ -2,6 +2,6 @@ contract c {
function f() public {} function f() public {}
} }
contract d { contract d {
function g() public { c(0).f(); } function g() public { c(address(0)).f(); }
} }
// ---- // ----

View File

@ -2,7 +2,7 @@ contract c {
function f() internal {} function f() internal {}
} }
contract d { 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.

View File

@ -2,7 +2,7 @@ contract c {
uint a; uint a;
} }
contract d { 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.

View File

@ -2,7 +2,7 @@ contract c {
uint public a; uint public a;
} }
contract d { 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

View File

@ -1,3 +1,3 @@
contract C { contract C {
C constant x = C(0x123); C constant x = C(address(0x123));
} }

View File

@ -256,7 +256,7 @@ contract Main {
A constant JU = JV; A constant JU = JV;
A constant JV = JW; A constant JV = JW;
A constant JW = JX; 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. // DeclarationError 7380: (6105-6123): Variable definition exhausting cyclic dependency validator.

View File

@ -131,5 +131,5 @@ contract Main {
A constant EZ = FA; A constant EZ = FA;
A constant FA = FB; A constant FA = FB;
A constant FB = FC; A constant FB = FC;
A constant FC = A(0x00); A constant FC = A(address(0x00));
} }

View File

@ -35,7 +35,7 @@ contract C
bytes10 m = bytes10(uint80(int80(-1))); bytes10 m = bytes10(uint80(int80(-1)));
m; m;
B n = B(uint(int(100))); B n = B(address(uint160(uint(int(100)))));
n; n;
} }
} }

View File

@ -3,7 +3,7 @@ contract C {
return this; return this;
} }
function g() pure public returns (bytes4) { function g() pure public returns (bytes4) {
C x = C(0x123); C x = C(address(0x123));
return x.f.selector; return x.f.selector;
} }
} }