Restrict experimental solidity to constantinople and above

This commit is contained in:
Nikola Matic 2023-05-17 16:21:37 +02:00
parent 33e7fc1cba
commit 7a34d34045
10 changed files with 23 additions and 4 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

@ -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.