Merge pull request #14239 from ethereum/restrict-experimental-mode-to-constantinople

Restrict experimental solidity to constantinople and above
This commit is contained in:
Nikola Matić 2023-05-17 19:06:36 +02:00 committed by GitHub
commit 4c77bf57df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 26 additions and 6 deletions

View File

@ -248,6 +248,8 @@ ASTPointer<PragmaDirective> Parser::parsePragmaDirective(bool const _finishedPar
if (literals.size() >= 2 && literals[0] == "experimental" && literals[1] == "solidity") if (literals.size() >= 2 && literals[0] == "experimental" && literals[1] == "solidity")
{ {
if (m_evmVersion < EVMVersion::constantinople())
fatalParserError(7637_error, "Experimental solidity requires Constantinople EVM version at the minimum.");
if (_finishedParsingTopLevelPragmas) if (_finishedParsingTopLevelPragmas)
fatalParserError(8185_error, "Experimental pragma \"solidity\" can only be set at the beginning of the source unit."); fatalParserError(8185_error, "Experimental pragma \"solidity\" can only be set at the beginning of the source unit.");
m_experimentalSolidityEnabledInCurrentSourceUnit = true; m_experimentalSolidityEnabledInCurrentSourceUnit = true;

View File

@ -110,7 +110,7 @@ do
SOL_FILES+=("$line") SOL_FILES+=("$line")
done < <( done < <(
grep --include "*.sol" -riL -E \ grep --include "*.sol" -riL -E \
"^\/\/ (Syntax|Type|Declaration)Error|^\/\/ ParserError (1684|2837|3716|3997|5333|6275|6281|6933|7319|8185)|^==== Source:" \ "^\/\/ (Syntax|Type|Declaration)Error|^\/\/ ParserError (1684|2837|3716|3997|5333|6275|6281|6933|7319|8185|7637)|^==== Source:" \
"${ROOT_DIR}/test/libsolidity/syntaxTests" \ "${ROOT_DIR}/test/libsolidity/syntaxTests" \
"${ROOT_DIR}/test/libsolidity/semanticTests" | "${ROOT_DIR}/test/libsolidity/semanticTests" |
# Skipping the unicode tests as I couldn't adapt the lexical grammar to recursively counting RLO/LRO/PDF's. # Skipping the unicode tests as I couldn't adapt the lexical grammar to recursively counting RLO/LRO/PDF's.

View File

@ -17,5 +17,5 @@
"src": "0:29:1" "src": "0:29:1"
} }
], ],
"src": "0:30:1" "src": "0:70:1"
} }

View File

@ -1,3 +1,4 @@
pragma experimental solidity; pragma experimental solidity;
// ====
// EVMVersion: >=constantinople
// ---- // ----

View File

@ -16,5 +16,5 @@
"src": "0:29:1" "src": "0:29:1"
} }
], ],
"src": "0:30:1" "src": "0:70:1"
} }

View File

@ -181,7 +181,8 @@ void ASTJSONTest::validateTestConfiguration() const
} }
} }
ASTJSONTest::ASTJSONTest(string const& _filename) ASTJSONTest::ASTJSONTest(string const& _filename):
EVMVersionRestrictedTestCase(_filename)
{ {
if (!boost::algorithm::ends_with(_filename, ".sol")) if (!boost::algorithm::ends_with(_filename, ".sol"))
BOOST_THROW_EXCEPTION(runtime_error("Invalid test contract file name: \"" + _filename + "\".")); BOOST_THROW_EXCEPTION(runtime_error("Invalid test contract file name: \"" + _filename + "\"."));

View File

@ -35,7 +35,7 @@ class CompilerStack;
namespace solidity::frontend::test namespace solidity::frontend::test
{ {
class ASTJSONTest: public TestCase class ASTJSONTest: public EVMVersionRestrictedTestCase
{ {
public: public:
struct TestVariant struct TestVariant

View File

@ -1,3 +1,5 @@
pragma experimental solidity; pragma experimental solidity;
// ====
// EVMVersion: >=constantinople
// ---- // ----
// Warning 2264: (0-29): Experimental features are turned on. Do not use experimental features on live deployments. // Warning 2264: (0-29): Experimental features are turned on. Do not use experimental features on live deployments.

View File

@ -18,6 +18,8 @@ import "A.sol";
contract D { contract D {
A a; A a;
} }
// ====
// EVMVersion: >=constantinople
// ---- // ----
// ParserError 2141: (B.sol:0-29): File declares "pragma experimental solidity". If you want to enable the experimental mode, all source units must include the pragma. // ParserError 2141: (B.sol:0-29): File declares "pragma experimental solidity". If you want to enable the experimental mode, all source units must include the pragma.
// ParserError 2141: (C.sol:0-29): File declares "pragma experimental solidity". If you want to enable the experimental mode, all source units must include the pragma. // ParserError 2141: (C.sol:0-29): File declares "pragma experimental solidity". If you want to enable the experimental mode, all source units must include the pragma.

View File

@ -1,5 +1,7 @@
contract A {} contract A {}
pragma experimental solidity; pragma experimental solidity;
// ====
// EVMVersion: >=constantinople
// ---- // ----
// ParserError 8185: (45-45): Experimental pragma "solidity" can only be set at the beginning of the source unit. // ParserError 8185: (45-45): Experimental pragma "solidity" can only be set at the beginning of the source unit.

View File

@ -9,5 +9,7 @@ struct A
{ {
uint256 x; uint256 x;
} }
// ====
// EVMVersion: >=constantinople
// ---- // ----
// ParserError 8185: (83-89): Experimental pragma "solidity" can only be set at the beginning of the source unit. // ParserError 8185: (83-89): Experimental pragma "solidity" can only be set at the beginning of the source unit.

View File

@ -0,0 +1,8 @@
pragma experimental solidity;
contract C {}
// ====
// EVMVersion: <constantinople
// ----
// ParserError 7637: (31-39): Experimental solidity requires Constantinople EVM version at the minimum.