From 423f3d3088dcb85819ed2094e5c48beac1411e69 Mon Sep 17 00:00:00 2001 From: a3d4 Date: Thu, 28 Apr 2022 03:59:27 +0200 Subject: [PATCH] Fix ICE caused by an immutable struct --- Changelog.md | 1 + libsolidity/interface/CompilerStack.cpp | 15 +++++++++------ .../immutable/non-value_type_struct.sol | 9 +++++++++ .../non-value_type_struct_with_mapping.sol | 9 +++++++++ 4 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 test/libsolidity/syntaxTests/immutable/non-value_type_struct.sol create mode 100644 test/libsolidity/syntaxTests/immutable/non-value_type_struct_with_mapping.sol diff --git a/Changelog.md b/Changelog.md index b37938172..374a84ffc 100644 --- a/Changelog.md +++ b/Changelog.md @@ -13,6 +13,7 @@ Compiler Features: Bugfixes: * ABI Encoder: When encoding an empty string coming from storage do not add a superfluous empty slot for data. * Yul Optimizer: Do not remove ``returndatacopy`` in cases in which it might perform out-of-bounds reads that unconditionally revert as out-of-gas. Previously, any ``returndatacopy`` that wrote to memory that was never read from was removed without accounting for the out-of-bounds condition. + * DocString Parser: Fix ICE caused by an immutable struct with mapping. ### 0.8.14 (2022-05-17) diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 6560b0be5..22321a16d 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -479,12 +479,6 @@ bool CompilerStack::analyze() if (auto sourceAst = source->ast) noErrors = contractLevelChecker.check(*sourceAst); - // Requires ContractLevelChecker - DocStringAnalyser docStringAnalyser(m_errorReporter); - for (Source const* source: m_sourceOrder) - if (source->ast && !docStringAnalyser.analyseDocStrings(*source->ast)) - noErrors = false; - // Now we run full type checks that go down to the expression level. This // cannot be done earlier, because we need cross-contract types and information // about whether a contract is abstract for the `new` expression. @@ -497,6 +491,15 @@ bool CompilerStack::analyze() if (source->ast && !typeChecker.checkTypeRequirements(*source->ast)) noErrors = false; + if (noErrors) + { + // Requires ContractLevelChecker and TypeChecker + DocStringAnalyser docStringAnalyser(m_errorReporter); + for (Source const* source: m_sourceOrder) + if (source->ast && !docStringAnalyser.analyseDocStrings(*source->ast)) + noErrors = false; + } + if (noErrors) { // Checks that can only be done when all types of all AST nodes are known. diff --git a/test/libsolidity/syntaxTests/immutable/non-value_type_struct.sol b/test/libsolidity/syntaxTests/immutable/non-value_type_struct.sol new file mode 100644 index 000000000..ad01e3b5e --- /dev/null +++ b/test/libsolidity/syntaxTests/immutable/non-value_type_struct.sol @@ -0,0 +1,9 @@ +contract Contract { + struct S { + int k; + } + + S immutable s; +} +// ---- +// TypeError 6377: (61-74): Immutable variables cannot have a non-value type. diff --git a/test/libsolidity/syntaxTests/immutable/non-value_type_struct_with_mapping.sol b/test/libsolidity/syntaxTests/immutable/non-value_type_struct_with_mapping.sol new file mode 100644 index 000000000..b734db30f --- /dev/null +++ b/test/libsolidity/syntaxTests/immutable/non-value_type_struct_with_mapping.sol @@ -0,0 +1,9 @@ +contract Contract { + struct S { + mapping(uint => address) map; + } + + S immutable s; +} +// ---- +// TypeError 6377: (84-97): Immutable variables cannot have a non-value type.