Adds support for structs in interfaces.

Closes #4733.
This commit is contained in:
Christian Parpart
2018-08-14 15:36:03 +02:00
committed by Christian Parpart
parent 8f0c2a46db
commit 81faafe7f2
5 changed files with 72 additions and 7 deletions
+62
View File
@@ -4755,6 +4755,68 @@ BOOST_AUTO_TEST_CASE(constructing_enums_from_ints)
ABI_CHECK(callContractFunction("test()"), encodeArgs(1));
}
BOOST_AUTO_TEST_CASE(struct_referencing)
{
static char const* sourceCode = R"(
pragma experimental ABIEncoderV2;
interface I {
struct S { uint a; }
}
library L {
struct S { uint b; uint a; }
function f() public pure returns (S) {
S memory s;
s.a = 3;
return s;
}
function g() public pure returns (I.S) {
I.S memory s;
s.a = 4;
return s;
}
// argument-dependant lookup tests
function a(I.S memory) public pure returns (uint) { return 1; }
function a(S memory) public pure returns (uint) { return 2; }
}
contract C is I {
function f() public pure returns (S) {
S memory s;
s.a = 1;
return s;
}
function g() public pure returns (I.S) {
I.S memory s;
s.a = 2;
return s;
}
function h() public pure returns (L.S) {
L.S memory s;
s.a = 5;
return s;
}
function x() public pure returns (L.S) {
return L.f();
}
function y() public pure returns (I.S) {
return L.g();
}
function a1() public pure returns (uint) { S memory s; return L.a(s); }
function a2() public pure returns (uint) { L.S memory s; return L.a(s); }
}
)";
compileAndRun(sourceCode, 0, "L");
ABI_CHECK(callContractFunction("f()"), encodeArgs(0, 3));
ABI_CHECK(callContractFunction("g()"), encodeArgs(4));
compileAndRun(sourceCode, 0, "C", bytes(), map<string, Address>{ {"L", m_contractAddress}});
ABI_CHECK(callContractFunction("f()"), encodeArgs(1));
ABI_CHECK(callContractFunction("g()"), encodeArgs(2));
ABI_CHECK(callContractFunction("h()"), encodeArgs(0, 5));
ABI_CHECK(callContractFunction("x()"), encodeArgs(0, 3));
ABI_CHECK(callContractFunction("y()"), encodeArgs(4));
ABI_CHECK(callContractFunction("a1()"), encodeArgs(1));
ABI_CHECK(callContractFunction("a2()"), encodeArgs(2));
}
BOOST_AUTO_TEST_CASE(enum_referencing)
{
char const* sourceCode = R"(
@@ -1,9 +1,6 @@
interface I {
struct A {
// This is currently expected to break, but it *may* change in the future.
int dummy;
}
}
// ----
// TypeError: (18-136): Structs cannot be defined in interfaces.
// TypeError: (120-129): Variables cannot be declared in interfaces.