Merge pull request #5995 from ethereum/incr-type-checker-cov

Add tests to increase TypeChecker.cpp coverage
This commit is contained in:
chriseth 2019-02-13 17:06:58 +01:00 committed by GitHub
commit 17817dc0ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 80 additions and 14 deletions

View File

@ -0,0 +1,7 @@
contract C {
function f(uint size) public {
new uint[1];
}
}
// ----
// TypeError: (60-67): Length has to be placed in parentheses after the array type for new expression.

View File

@ -0,0 +1,9 @@
// This used to cause an internal error because of the visitation order.
contract Test {
struct S { uint a; }
function f() public {
new S();
}
}
// ----
// TypeError: (147-152): Identifier is not a contract.

View File

@ -0,0 +1,9 @@
contract Base {
constructor(uint8) public {}
}
contract Derived is Base(300) { }
contract Derived2 is Base {
constructor() Base(2) public { }
}
// ----
// TypeError: (74-77): Invalid type for argument in constructor call. Invalid implicit conversion from int_const 300 to uint8 requested.

View File

@ -0,0 +1,13 @@
contract C {
function a(uint256) public returns (uint) { return 1; }
function a(uint8) public returns (uint) { return 1; }
function f() public returns (C) { return this; }
function g() internal returns (function(uint8) internal returns(uint))
{
return f().a;
}
}
// ----
// TypeError: (282-287): Member "a" not unique after argument-dependent lookup in contract C.

View File

@ -0,0 +1,13 @@
contract C {
function value(uint256) public returns (uint) { return 1; }
function value(uint8) public returns (uint) { return 1; }
function f() public returns (C) { return this; }
function g() internal returns (function(uint8) internal returns(uint))
{
return f().value;
}
}
// ----
// TypeError: (290-299): Member "value" not unique after argument-dependent lookup in contract C - did you forget the "payable" modifier?

View File

@ -0,0 +1,5 @@
contract test {
function f() public returns (uint256 r, uint8) { return ((12, "")); }
}
// ----
// TypeError: (76-86): Return argument type tuple(int_const 12,literal_string "") is not implicitly convertible to expected type tuple(uint256,uint8).

View File

@ -0,0 +1,8 @@
contract C {
function f() internal pure {
var i = 31415999999999999999999999999999999999999999999999999999999999999999933**3;
var unreachable = 123;
}
}
// ----
// TypeError: (62-136): Invalid rational int_const 3100...(204 digits omitted)...9237 (absolute value too large or division by zero).

View File

@ -6,6 +6,7 @@ contract C {
return x;
}
function f() internal pure {
var s = -31415;
var i = 31415;
var t = "string";
var g2 = g;
@ -19,17 +20,18 @@ contract C {
}
}
// ----
// SyntaxError: (224-237): Use of the "var" keyword is disallowed. Use explicit declaration `uint16 i = ...´ instead.
// SyntaxError: (247-263): Use of the "var" keyword is disallowed. Use explicit declaration `string memory t = ...´ instead.
// SyntaxError: (273-283): Use of the "var" keyword is disallowed. Use explicit declaration `function (uint256) pure returns (uint256) g2 = ...´ instead.
// SyntaxError: (293-326): Use of the "var" keyword is disallowed. Type cannot be expressed in syntax.
// SyntaxError: (336-360): Use of the "var" keyword is disallowed. Use explicit declaration `(uint8 a, string memory b) = ...´ instead.
// SyntaxError: (370-387): Use of the "var" keyword is disallowed. Use explicit declaration `(uint256 x, , uint256 z) = ...´ instead.
// TypeError: (397-414): Different number of components on the left hand side (2) than on the right hand side (1).
// SyntaxError: (397-414): Use of the "var" keyword is disallowed. Type cannot be expressed in syntax.
// TypeError: (424-440): Different number of components on the left hand side (2) than on the right hand side (1).
// SyntaxError: (424-440): Use of the "var" keyword is disallowed. Type cannot be expressed in syntax.
// TypeError: (450-464): Different number of components on the left hand side (2) than on the right hand side (1).
// SyntaxError: (450-464): Use of the "var" keyword is disallowed. Type cannot be expressed in syntax.
// TypeError: (474-489): Different number of components on the left hand side (2) than on the right hand side (1).
// SyntaxError: (474-489): Use of the "var" keyword is disallowed. Type cannot be expressed in syntax.
// SyntaxError: (224-238): Use of the "var" keyword is disallowed. Use explicit declaration `int16 s = ...´ instead.
// SyntaxError: (248-261): Use of the "var" keyword is disallowed. Use explicit declaration `uint16 i = ...´ instead.
// SyntaxError: (271-287): Use of the "var" keyword is disallowed. Use explicit declaration `string memory t = ...´ instead.
// SyntaxError: (297-307): Use of the "var" keyword is disallowed. Use explicit declaration `function (uint256) pure returns (uint256) g2 = ...´ instead.
// SyntaxError: (317-350): Use of the "var" keyword is disallowed. Type cannot be expressed in syntax.
// SyntaxError: (360-384): Use of the "var" keyword is disallowed. Use explicit declaration `(uint8 a, string memory b) = ...´ instead.
// SyntaxError: (394-411): Use of the "var" keyword is disallowed. Use explicit declaration `(uint256 x, , uint256 z) = ...´ instead.
// TypeError: (421-438): Different number of components on the left hand side (2) than on the right hand side (1).
// SyntaxError: (421-438): Use of the "var" keyword is disallowed. Type cannot be expressed in syntax.
// TypeError: (448-464): Different number of components on the left hand side (2) than on the right hand side (1).
// SyntaxError: (448-464): Use of the "var" keyword is disallowed. Type cannot be expressed in syntax.
// TypeError: (474-488): Different number of components on the left hand side (2) than on the right hand side (1).
// SyntaxError: (474-488): Use of the "var" keyword is disallowed. Type cannot be expressed in syntax.
// TypeError: (498-513): Different number of components on the left hand side (2) than on the right hand side (1).
// SyntaxError: (498-513): Use of the "var" keyword is disallowed. Type cannot be expressed in syntax.