Tests after changing type of super to TypeType

This commit is contained in:
hrkrshnn 2020-10-14 11:18:22 +02:00
parent 9eafa1fa1a
commit 2348b721bb
14 changed files with 126 additions and 36 deletions

View File

@ -1596,7 +1596,6 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
solAssert(false, "Blockhash has been removed.");
else if (member == "creationCode" || member == "runtimeCode")
{
// FIXME For super this needs to be fixed
TypePointer arg = dynamic_cast<MagicType const&>(*_memberAccess.expression().annotation().type).typeArgument();
auto const& contractType = dynamic_cast<ContractType const&>(*arg);
solAssert(!contractType.isSuper(), "");

View File

@ -11,7 +11,7 @@ contract C {
}
}
contract Test {
contract Test is C {
function c() public pure returns (string memory) {
return type(C).name;
}
@ -21,9 +21,13 @@ contract Test {
function i() public pure returns (string memory) {
return type(I).name;
}
function j() public pure returns (string memory) {
return type(super).name;
}
}
// ----
// c() -> 0x20, 1, "C"
// a() -> 0x20, 1, "A"
// i() -> 0x20, 1, "I"
// j() -> 0x20, 1, "C"

View File

@ -0,0 +1,54 @@
pragma experimental ABIEncoderV2;
function compareStrings(string memory s1, string memory s2) returns (bool) {
return keccak256(abi.encodePacked(s1)) == keccak256(abi.encodePacked(s2));
}
contract A {
string[] r;
function f() public virtual returns (bool) {
r.push("");
return false;
}
}
contract B is A {
function f() public virtual override returns (bool) {
super.f();
r.push(type(super).name);
return false;
}
}
contract C is A {
function f() public virtual override returns (bool) {
super.f();
r.push(type(super).name);
return false;
}
}
contract D is B, C {
function f() public override(B, C) returns (bool) {
super.f();
r.push(type(super).name);
// Order of calls: D.f, C.f, B.f, A.f
// r contains "", "A", "B", "C"
assert(r.length == 4);
assert(compareStrings(r[0], ""));
assert(compareStrings(r[1], "A"));
assert(compareStrings(r[2], "B"));
assert(compareStrings(r[3], "C"));
return true;
}
}
// ----
// f() -> true

View File

@ -84,5 +84,7 @@ contract InternalCall {
// Warning 2018: (1212-1274): Function state mutability can be restricted to pure
// Warning 2018: (1280-1342): Function state mutability can be restricted to pure
// Warning 4588: (771-814): Assertion checker does not yet implement this type of function call.
// Warning 8364: (825-830): Assertion checker does not yet implement type type(contract super ContractWithFunctionNotCalled2)
// Warning 4588: (771-814): Assertion checker does not yet implement this type of function call.
// Warning 8364: (825-830): Assertion checker does not yet implement type type(contract super ContractWithFunctionNotCalled2)
// Warning 5729: (1403-1408): BMC does not yet implement this type of function call.

View File

@ -19,9 +19,9 @@ contract C {
}
}
// ----
// TypeError 2271: (144-157): Operator != not compatible with types contract super C and contract C
// TypeError 2271: (167-180): Operator != not compatible with types contract C and contract super C
// TypeError 2271: (254-264): Operator != not compatible with types contract super C and contract C
// TypeError 2271: (274-284): Operator != not compatible with types contract C and contract super C
// TypeError 2271: (349-359): Operator != not compatible with types contract super C and contract D
// TypeError 2271: (369-379): Operator != not compatible with types contract D and contract super C
// TypeError 2271: (144-157): Operator != not compatible with types type(contract super C) and contract C
// TypeError 2271: (167-180): Operator != not compatible with types contract C and type(contract super C)
// TypeError 2271: (254-264): Operator != not compatible with types type(contract super C) and contract C
// TypeError 2271: (274-284): Operator != not compatible with types contract C and type(contract super C)
// TypeError 2271: (349-359): Operator != not compatible with types type(contract super C) and contract D
// TypeError 2271: (369-379): Operator != not compatible with types contract D and type(contract super C)

View File

@ -30,27 +30,27 @@ contract C {
}
}
// ----
// TypeError 2271: (49-62): Operator << not compatible with types contract super C and contract C
// TypeError 2271: (72-85): Operator >> not compatible with types contract super C and contract C
// TypeError 2271: (95-107): Operator ^ not compatible with types contract super C and contract C
// TypeError 2271: (117-129): Operator | not compatible with types contract super C and contract C
// TypeError 2271: (139-151): Operator & not compatible with types contract super C and contract C
// TypeError 2271: (162-174): Operator * not compatible with types contract super C and contract C
// TypeError 2271: (184-196): Operator / not compatible with types contract super C and contract C
// TypeError 2271: (206-218): Operator % not compatible with types contract super C and contract C
// TypeError 2271: (228-240): Operator - not compatible with types contract super C and contract C
// TypeError 2271: (250-262): Operator + not compatible with types contract super C and contract C
// TypeError 2271: (272-285): Operator ** not compatible with types contract super C and contract C
// TypeError 2271: (296-309): Operator == not compatible with types contract super C and contract C
// TypeError 2271: (319-332): Operator != not compatible with types contract super C and contract C
// TypeError 2271: (342-355): Operator >= not compatible with types contract super C and contract C
// TypeError 2271: (365-378): Operator <= not compatible with types contract super C and contract C
// TypeError 2271: (388-400): Operator < not compatible with types contract super C and contract C
// TypeError 2271: (410-422): Operator > not compatible with types contract super C and contract C
// TypeError 2271: (433-446): Operator || not compatible with types contract super C and contract C
// TypeError 2271: (456-469): Operator && not compatible with types contract super C and contract C
// TypeError 2271: (49-62): Operator << not compatible with types type(contract super C) and contract C
// TypeError 2271: (72-85): Operator >> not compatible with types type(contract super C) and contract C
// TypeError 2271: (95-107): Operator ^ not compatible with types type(contract super C) and contract C
// TypeError 2271: (117-129): Operator | not compatible with types type(contract super C) and contract C
// TypeError 2271: (139-151): Operator & not compatible with types type(contract super C) and contract C
// TypeError 2271: (162-174): Operator * not compatible with types type(contract super C) and contract C
// TypeError 2271: (184-196): Operator / not compatible with types type(contract super C) and contract C
// TypeError 2271: (206-218): Operator % not compatible with types type(contract super C) and contract C
// TypeError 2271: (228-240): Operator - not compatible with types type(contract super C) and contract C
// TypeError 2271: (250-262): Operator + not compatible with types type(contract super C) and contract C
// TypeError 2271: (272-285): Operator ** not compatible with types type(contract super C) and contract C
// TypeError 2271: (296-309): Operator == not compatible with types type(contract super C) and contract C
// TypeError 2271: (319-332): Operator != not compatible with types type(contract super C) and contract C
// TypeError 2271: (342-355): Operator >= not compatible with types type(contract super C) and contract C
// TypeError 2271: (365-378): Operator <= not compatible with types type(contract super C) and contract C
// TypeError 2271: (388-400): Operator < not compatible with types type(contract super C) and contract C
// TypeError 2271: (410-422): Operator > not compatible with types type(contract super C) and contract C
// TypeError 2271: (433-446): Operator || not compatible with types type(contract super C) and contract C
// TypeError 2271: (456-469): Operator && not compatible with types type(contract super C) and contract C
// TypeError 4247: (480-485): Expression has to be an lvalue.
// TypeError 7366: (480-493): Operator -= not compatible with types contract super C and contract C
// TypeError 7366: (480-493): Operator -= not compatible with types type(contract super C) and contract C
// TypeError 4247: (503-508): Expression has to be an lvalue.
// TypeError 7366: (503-516): Operator += not compatible with types contract super C and contract C
// TypeError 1080: (527-546): True expression's type contract super C does not match false expression's type contract C.
// TypeError 7366: (503-516): Operator += not compatible with types type(contract super C) and contract C
// TypeError 1080: (527-546): True expression's type type(contract super C) does not match false expression's type contract C.

View File

@ -12,4 +12,4 @@ contract B is S
}
}
// ----
// TypeError 9640: (129-137): Explicit type conversion not allowed from "contract super B" to "contract S".
// TypeError 9640: (129-137): Explicit type conversion not allowed from "type(contract super B)" to "contract S".

View File

@ -7,4 +7,4 @@ contract B is A {
}
}
// ----
// TypeError 9582: (123-130): Member "f" not found or not visible after argument-dependent lookup in contract super B.
// TypeError 9582: (123-130): Member "f" not found or not visible after argument-dependent lookup in type(contract super B).

View File

@ -0,0 +1,14 @@
contract Other {
function f(uint) public pure returns (uint) {}
}
contract SuperTest is Other {
function creationSuper() public pure returns (bytes memory) {
return type(super).creationCode;
}
function runtimeOther() public pure returns (bytes memory) {
return type(super).runtimeCode;
}
}
// ----
// TypeError 3625: (172-196): "creationCode" and "runtimeCode" are not available for the "super" contract.
// TypeError 3625: (272-295): "creationCode" and "runtimeCode" are not available for the "super" contract.

View File

@ -0,0 +1,17 @@
interface ERC165 {
/// @notice Query if a contract implements an interface
/// @param interfaceID The interface identifier, as specified in ERC-165
/// @dev Interface identification is specified in ERC-165. This function
/// uses less than 30,000 gas.
/// @return `true` if the contract implements `interfaceID` and
/// `interfaceID` is not 0xffffffff, `false` otherwise
function supportsInterface(bytes4 interfaceID) external view returns (bool);
}
abstract contract Test is ERC165 {
function hello() public pure returns (bytes4 data){
return type(super).interfaceID;
}
}
// ----
// TypeError 9582: (587-610): Member "interfaceID" not found or not visible after argument-dependent lookup in type(contract super Test).

View File

@ -8,4 +8,4 @@ contract B is A {
}
}
// ----
// TypeError 9582: (95-102): Member "f" not found or not visible after argument-dependent lookup in contract super B.
// TypeError 9582: (95-102): Member "f" not found or not visible after argument-dependent lookup in type(contract super B).

View File

@ -6,4 +6,4 @@ contract C is B {
bytes4 constant s4 = super.g.selector;
}
// ----
// TypeError 9582: (93-100): Member "g" not found or not visible after argument-dependent lookup in contract super C.
// TypeError 9582: (93-100): Member "g" not found or not visible after argument-dependent lookup in type(contract super C).

View File

@ -5,4 +5,4 @@ contract b is a {
function f() public override { super.f(); }
}
// ----
// TypeError 9582: (110-117): Member "f" not found or not visible after argument-dependent lookup in contract super b.
// TypeError 9582: (110-117): Member "f" not found or not visible after argument-dependent lookup in type(contract super b).

View File

@ -9,4 +9,4 @@ contract c is a,b {
function f() public override(a, b) { super.f(); }
}
// ----
// TypeError 9582: (118-125): Member "f" not found or not visible after argument-dependent lookup in contract super b.
// TypeError 9582: (118-125): Member "f" not found or not visible after argument-dependent lookup in type(contract super b).