mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #10096 from ethereum/pragmaabicoder
Introduce abicoder pragma.
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
#include <libsolidity/codegen/Compiler.h>
|
||||
#include <libsolidity/ast/AST.h>
|
||||
#include <libsolidity/analysis/TypeChecker.h>
|
||||
#include <libsolidity/analysis/SyntaxChecker.h>
|
||||
#include <liblangutil/ErrorReporter.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
@@ -61,6 +62,7 @@ evmasm::AssemblyItems compileContract(std::shared_ptr<CharStream> _sourceCode)
|
||||
BOOST_CHECK(!!sourceUnit);
|
||||
|
||||
Scoper::assignScopes(*sourceUnit);
|
||||
BOOST_REQUIRE(SyntaxChecker(errorReporter, false).checkSyntax(*sourceUnit));
|
||||
GlobalContext globalContext;
|
||||
NameAndTypeResolver resolver(globalContext, solidity::test::CommonOptions::get().evmVersion(), errorReporter);
|
||||
DeclarationTypeChecker declarationTypeChecker(errorReporter, solidity::test::CommonOptions::get().evmVersion());
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <libsolidity/parsing/Parser.h>
|
||||
#include <libsolidity/analysis/NameAndTypeResolver.h>
|
||||
#include <libsolidity/analysis/Scoper.h>
|
||||
#include <libsolidity/analysis/SyntaxChecker.h>
|
||||
#include <libsolidity/analysis/DeclarationTypeChecker.h>
|
||||
#include <libsolidity/codegen/CompilerContext.h>
|
||||
#include <libsolidity/codegen/ExpressionCompiler.h>
|
||||
@@ -93,18 +94,20 @@ Declaration const& resolveDeclaration(
|
||||
}
|
||||
|
||||
bytes compileFirstExpression(
|
||||
const string& _sourceCode,
|
||||
string const& _sourceCode,
|
||||
vector<vector<string>> _functions = {},
|
||||
vector<vector<string>> _localVariables = {}
|
||||
)
|
||||
{
|
||||
string sourceCode = "pragma solidity >=0.0; // SPDX-License-Identifier: GPL-3\n" + _sourceCode;
|
||||
|
||||
ASTPointer<SourceUnit> sourceUnit;
|
||||
try
|
||||
{
|
||||
ErrorList errors;
|
||||
ErrorReporter errorReporter(errors);
|
||||
sourceUnit = Parser(errorReporter, solidity::test::CommonOptions::get().evmVersion()).parse(
|
||||
make_shared<Scanner>(CharStream(_sourceCode, ""))
|
||||
make_shared<Scanner>(CharStream(sourceCode, ""))
|
||||
);
|
||||
if (!sourceUnit)
|
||||
return bytes();
|
||||
@@ -119,6 +122,7 @@ bytes compileFirstExpression(
|
||||
ErrorReporter errorReporter(errors);
|
||||
GlobalContext globalContext;
|
||||
Scoper::assignScopes(*sourceUnit);
|
||||
BOOST_REQUIRE(SyntaxChecker(errorReporter, false).checkSyntax(*sourceUnit));
|
||||
NameAndTypeResolver resolver(globalContext, solidity::test::CommonOptions::get().evmVersion(), errorReporter);
|
||||
resolver.registerDeclarations(*sourceUnit);
|
||||
BOOST_REQUIRE_MESSAGE(resolver.resolveNamesAndTypes(*sourceUnit), "Resolving names failed");
|
||||
@@ -186,7 +190,7 @@ BOOST_AUTO_TEST_CASE(literal_false)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract test {
|
||||
function f() { bool x = false; }
|
||||
function f() public { bool x = false; }
|
||||
}
|
||||
)";
|
||||
bytes code = compileFirstExpression(sourceCode);
|
||||
@@ -199,7 +203,7 @@ BOOST_AUTO_TEST_CASE(int_literal)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract test {
|
||||
function f() { uint x = 0x12345678901234567890; }
|
||||
function f() public { uint x = 0x12345678901234567890; }
|
||||
}
|
||||
)";
|
||||
bytes code = compileFirstExpression(sourceCode);
|
||||
@@ -228,7 +232,7 @@ BOOST_AUTO_TEST_CASE(int_with_gwei_ether_subdenomination)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract test {
|
||||
function test () {
|
||||
function f() public {
|
||||
uint x = 1 gwei;
|
||||
}
|
||||
}
|
||||
@@ -258,7 +262,7 @@ BOOST_AUTO_TEST_CASE(comparison)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract test {
|
||||
function f() { bool x = (0x10aa < 0x11aa) != true; }
|
||||
function f() public { bool x = (0x10aa < 0x11aa) != true; }
|
||||
}
|
||||
)";
|
||||
bytes code = compileFirstExpression(sourceCode);
|
||||
@@ -290,7 +294,7 @@ BOOST_AUTO_TEST_CASE(short_circuiting)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract test {
|
||||
function f() { bool x = true != (4 <= 8 + 10 || 9 != 2); }
|
||||
function f() public { bool x = true != (4 <= 8 + 10 || 9 != 2); }
|
||||
}
|
||||
)";
|
||||
bytes code = compileFirstExpression(sourceCode);
|
||||
@@ -321,7 +325,7 @@ BOOST_AUTO_TEST_CASE(arithmetic)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract test {
|
||||
function f(uint y) { ((((((((y ^ 8) & 7) | 6) - 5) + 4) % 3) / 2) * 1); }
|
||||
function f(uint y) public { ((((((((y ^ 8) & 7) | 6) - 5) + 4) % 3) / 2) * 1); }
|
||||
}
|
||||
)";
|
||||
bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "y"}});
|
||||
@@ -402,7 +406,7 @@ BOOST_AUTO_TEST_CASE(unary_operators)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract test {
|
||||
function f(int y) { !(~- y == 2); }
|
||||
function f(int y) public { !(~- y == 2); }
|
||||
}
|
||||
)";
|
||||
bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "y"}});
|
||||
@@ -492,7 +496,7 @@ BOOST_AUTO_TEST_CASE(assignment)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract test {
|
||||
function f(uint a, uint b) { (a += b) * 2; }
|
||||
function f(uint a, uint b) public { (a += b) * 2; }
|
||||
}
|
||||
)";
|
||||
bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "a"}, {"test", "f", "b"}});
|
||||
@@ -530,7 +534,7 @@ BOOST_AUTO_TEST_CASE(negative_literals_8bits)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract test {
|
||||
function f() { int8 x = -0x80; }
|
||||
function f() public { int8 x = -0x80; }
|
||||
}
|
||||
)";
|
||||
bytes code = compileFirstExpression(sourceCode);
|
||||
@@ -543,7 +547,7 @@ BOOST_AUTO_TEST_CASE(negative_literals_16bits)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract test {
|
||||
function f() { int64 x = ~0xabc; }
|
||||
function f() public { int64 x = ~0xabc; }
|
||||
}
|
||||
)";
|
||||
bytes code = compileFirstExpression(sourceCode);
|
||||
@@ -558,7 +562,7 @@ BOOST_AUTO_TEST_CASE(intermediately_overflowing_literals)
|
||||
// have been applied
|
||||
char const* sourceCode = R"(
|
||||
contract test {
|
||||
function f() { uint8 x = (0x00ffffffffffffffffffffffffffffffffffffffff * 0xffffffffffffffffffffffffff01) & 0xbf; }
|
||||
function f() public { uint8 x = (0x00ffffffffffffffffffffffffffffffffffffffff * 0xffffffffffffffffffffffffff01) & 0xbf; }
|
||||
}
|
||||
)";
|
||||
bytes code = compileFirstExpression(sourceCode);
|
||||
@@ -571,7 +575,7 @@ BOOST_AUTO_TEST_CASE(blockhash)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract test {
|
||||
function f() {
|
||||
function f() public {
|
||||
blockhash(3);
|
||||
}
|
||||
}
|
||||
@@ -603,7 +607,7 @@ BOOST_AUTO_TEST_CASE(selfbalance)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract test {
|
||||
function f() returns (uint) {
|
||||
function f() public returns (uint) {
|
||||
return address(this).balance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
pragma experimental ABIEncoderV2;
|
||||
pragma abicoder v1;
|
||||
// ----
|
||||
// SyntaxError 3845: (34-53): ABI coder has already been selected for this source unit.
|
||||
@@ -0,0 +1,4 @@
|
||||
pragma abicoder v1;
|
||||
pragma experimental ABIEncoderV2;
|
||||
// ----
|
||||
// SyntaxError 8273: (20-53): ABI coder v1 has already been selected through "pragma abicoder v1".
|
||||
@@ -0,0 +1,3 @@
|
||||
pragma abicoder something;
|
||||
// ----
|
||||
// SyntaxError 2745: (0-26): Expected either "pragma abicoder v1" or "pragma abicoder v2".
|
||||
@@ -0,0 +1,4 @@
|
||||
pragma experimental ABIEncoderV2;
|
||||
pragma abicoder v2;
|
||||
// ----
|
||||
// SyntaxError 3845: (34-53): ABI coder has already been selected for this source unit.
|
||||
@@ -0,0 +1 @@
|
||||
pragma abicoder v1;
|
||||
@@ -0,0 +1,4 @@
|
||||
pragma abicoder v1;
|
||||
pragma abicoder v1;
|
||||
// ----
|
||||
// SyntaxError 3845: (20-39): ABI coder has already been selected for this source unit.
|
||||
@@ -0,0 +1,2 @@
|
||||
pragma abicoder v2;
|
||||
pragma experimental ABIEncoderV2;
|
||||
+1
-1
@@ -17,4 +17,4 @@ contract Test {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 2443: (B:71-80): The type of this parameter, struct C.Item, is only supported in ABIEncoderV2. Use "pragma experimental ABIEncoderV2;" to enable the feature.
|
||||
// TypeError 2443: (B:71-80): The type of this parameter, struct C.Item, is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
|
||||
|
||||
+1
-1
@@ -17,4 +17,4 @@ contract Test {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 2443: (B:90-100): The type of this parameter, struct C.Item, is only supported in ABIEncoderV2. Use "pragma experimental ABIEncoderV2;" to enable the feature.
|
||||
// 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.
|
||||
|
||||
+1
-1
@@ -19,4 +19,4 @@ contract Test {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 2443: (B:146-155): The type of this parameter, struct C.Item, is only supported in ABIEncoderV2. Use "pragma experimental ABIEncoderV2;" to enable the feature.
|
||||
// TypeError 2443: (B:146-155): The type of this parameter, struct C.Item, is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
|
||||
|
||||
+1
-1
@@ -13,4 +13,4 @@ contract D {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 2428: (B:65-76): The type of return parameter 1, string[], is only supported in ABIEncoderV2. Use "pragma experimental ABIEncoderV2;" to enable the feature.
|
||||
// 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.
|
||||
|
||||
+1
-1
@@ -17,4 +17,4 @@ contract Test {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 2428: (B:70-83): The type of return parameter 1, struct C.Item, is only supported in ABIEncoderV2. Use "pragma experimental ABIEncoderV2;" to enable the feature.
|
||||
// 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.
|
||||
|
||||
+1
-1
@@ -17,4 +17,4 @@ contract Test {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 2428: (B:70-83): The type of return parameter 1, struct C.Item, is only supported in ABIEncoderV2. Use "pragma experimental ABIEncoderV2;" to enable the feature.
|
||||
// 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.
|
||||
|
||||
@@ -16,4 +16,4 @@ contract Test {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 2443: (B:74-84): The type of this parameter, struct L.Item, is only supported in ABIEncoderV2. Use "pragma experimental ABIEncoderV2;" to enable the feature.
|
||||
// TypeError 2443: (B:74-84): The type of this parameter, struct L.Item, is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
|
||||
|
||||
+1
-1
@@ -19,4 +19,4 @@ contract D {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 2428: (B:86-97): The type of return parameter 1, struct L.Item, is only supported in ABIEncoderV2. Use "pragma experimental ABIEncoderV2;" to enable the feature.
|
||||
// TypeError 2428: (B:86-97): The type of return parameter 1, struct L.Item, is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
|
||||
|
||||
+1
-1
@@ -17,4 +17,4 @@ contract Test {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 2428: (B:70-77): The type of return parameter 1, struct L.Item, is only supported in ABIEncoderV2. Use "pragma experimental ABIEncoderV2;" to enable the feature.
|
||||
// TypeError 2428: (B:70-77): The type of return parameter 1, struct L.Item, is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
|
||||
|
||||
+1
-1
@@ -13,4 +13,4 @@ import "A";
|
||||
|
||||
contract D is C {}
|
||||
// ----
|
||||
// TypeError 6594: (B:13-31): Contract "D" does not use ABIEncoderV2 but wants to inherit from a contract which uses types that require it. Use "pragma experimental ABIEncoderV2;" for the inheriting contract as well to enable the feature.
|
||||
// TypeError 6594: (B:13-31): Contract "D" does not use ABI coder v2 but wants to inherit from a contract which uses types that require it. Use "pragma abicoder v2;" for the inheriting contract as well to enable the feature.
|
||||
|
||||
+1
-1
@@ -13,4 +13,4 @@ import "A";
|
||||
|
||||
contract D is C {}
|
||||
// ----
|
||||
// TypeError 6594: (B:13-31): Contract "D" does not use ABIEncoderV2 but wants to inherit from a contract which uses types that require it. Use "pragma experimental ABIEncoderV2;" for the inheriting contract as well to enable the feature.
|
||||
// TypeError 6594: (B:13-31): Contract "D" does not use ABI coder v2 but wants to inherit from a contract which uses types that require it. Use "pragma abicoder v2;" for the inheriting contract as well to enable the feature.
|
||||
|
||||
@@ -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 ABIEncoderV2. Use "pragma experimental ABIEncoderV2;" to enable the feature.
|
||||
// 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.
|
||||
|
||||
@@ -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 ABIEncoderV2. Use "pragma experimental ABIEncoderV2;" to enable the feature.
|
||||
// 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.
|
||||
|
||||
@@ -3,5 +3,5 @@ contract Test {
|
||||
function g(uint[][1] calldata) external { }
|
||||
}
|
||||
// ----
|
||||
// TypeError 4957: (31-48): This type is only supported in ABIEncoderV2. Use "pragma experimental ABIEncoderV2;" to enable the feature.
|
||||
// TypeError 4957: (78-96): This type is only supported in ABIEncoderV2. Use "pragma experimental ABIEncoderV2;" to enable the feature.
|
||||
// TypeError 4957: (31-48): This type is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
|
||||
// TypeError 4957: (78-96): This type is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
|
||||
|
||||
@@ -2,4 +2,4 @@ contract C {
|
||||
constructor(uint[][][] memory t) {}
|
||||
}
|
||||
// ----
|
||||
// TypeError 4957: (26-45): This type is only supported in ABIEncoderV2. Use "pragma experimental ABIEncoderV2;" to enable the feature. Alternatively, make the contract abstract and supply the constructor arguments from a derived contract.
|
||||
// TypeError 4957: (26-45): This type is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature. Alternatively, make the contract abstract and supply the constructor arguments from a derived contract.
|
||||
|
||||
@@ -2,4 +2,4 @@ contract c {
|
||||
event E(uint[][]);
|
||||
}
|
||||
// ----
|
||||
// TypeError 3061: (25-33): This type is only supported in ABIEncoderV2. Use "pragma experimental ABIEncoderV2;" to enable the feature.
|
||||
// TypeError 3061: (25-33): This type is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
|
||||
|
||||
@@ -3,4 +3,4 @@ contract c {
|
||||
event E(S);
|
||||
}
|
||||
// ----
|
||||
// TypeError 3061: (61-62): This type is only supported in ABIEncoderV2. Use "pragma experimental ABIEncoderV2;" to enable the feature.
|
||||
// TypeError 3061: (61-62): This type is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
|
||||
|
||||
@@ -3,4 +3,4 @@ contract c {
|
||||
event E(S);
|
||||
}
|
||||
// ----
|
||||
// TypeError 3061: (51-52): This type is only supported in ABIEncoderV2. Use "pragma experimental ABIEncoderV2;" to enable the feature.
|
||||
// TypeError 3061: (51-52): This type is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
|
||||
|
||||
@@ -3,4 +3,4 @@ contract c {
|
||||
event E(S indexed);
|
||||
}
|
||||
// ----
|
||||
// TypeError 3061: (51-60): This type is only supported in ABIEncoderV2. Use "pragma experimental ABIEncoderV2;" to enable the feature.
|
||||
// TypeError 3061: (51-60): This type is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
|
||||
|
||||
@@ -8,4 +8,4 @@ contract C {
|
||||
mapping(uint256 => X) public m;
|
||||
}
|
||||
// ----
|
||||
// TypeError 2763: (88-118): The following types are only supported for getters in ABIEncoderV2: struct C.Y memory. Either remove "public" or use "pragma experimental ABIEncoderV2;" to enable the feature.
|
||||
// TypeError 2763: (88-118): The following types are only supported for getters in ABI coder v2: struct C.Y memory. Either remove "public" or use "pragma abicoder v2;" to enable the feature.
|
||||
|
||||
@@ -16,4 +16,4 @@ contract B is A { }
|
||||
import "./B.sol";
|
||||
contract C is B { }
|
||||
// ----
|
||||
// TypeError 6594: (C.sol:18-37): Contract "C" does not use ABIEncoderV2 but wants to inherit from a contract which uses types that require it. Use "pragma experimental ABIEncoderV2;" for the inheriting contract as well to enable the feature.
|
||||
// TypeError 6594: (C.sol:18-37): Contract "C" does not use ABI coder v2 but wants to inherit from a contract which uses types that require it. Use "pragma abicoder v2;" for the inheriting contract as well to enable the feature.
|
||||
|
||||
@@ -14,4 +14,4 @@ contract B is A { }
|
||||
import "./B.sol";
|
||||
contract C is B { }
|
||||
// ----
|
||||
// TypeError 6594: (B.sol:18-37): Contract "B" does not use ABIEncoderV2 but wants to inherit from a contract which uses types that require it. Use "pragma experimental ABIEncoderV2;" for the inheriting contract as well to enable the feature.
|
||||
// TypeError 6594: (B.sol:18-37): Contract "B" does not use ABI coder v2 but wants to inherit from a contract which uses types that require it. Use "pragma abicoder v2;" for the inheriting contract as well to enable the feature.
|
||||
|
||||
+1
-1
@@ -2,4 +2,4 @@ contract C {
|
||||
function f() public pure returns (string[][] memory) {}
|
||||
}
|
||||
// ----
|
||||
// TypeError 4957: (51-68): This type is only supported in ABIEncoderV2. Use "pragma experimental ABIEncoderV2;" to enable the feature.
|
||||
// TypeError 4957: (51-68): This type is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
|
||||
|
||||
+1
-1
@@ -2,4 +2,4 @@ contract C {
|
||||
function f() public pure returns (uint[][2] memory) {}
|
||||
}
|
||||
// ----
|
||||
// TypeError 4957: (51-67): This type is only supported in ABIEncoderV2. Use "pragma experimental ABIEncoderV2;" to enable the feature.
|
||||
// TypeError 4957: (51-67): This type is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
|
||||
|
||||
+1
-1
@@ -3,4 +3,4 @@ contract C {
|
||||
function f() public pure returns (S memory x) {}
|
||||
}
|
||||
// ----
|
||||
// TypeError 4957: (80-90): This type is only supported in ABIEncoderV2. Use "pragma experimental ABIEncoderV2;" to enable the feature.
|
||||
// TypeError 4957: (80-90): This type is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
|
||||
|
||||
Reference in New Issue
Block a user