Fix CompilerStack::loadMissingSources()

- FatalError Exception was not caught
- fixes #8102
This commit is contained in:
Alexander Arlt
2020-02-12 11:22:11 -05:00
parent 85348e9af7
commit d0eeca8014
2 changed files with 555 additions and 27 deletions
+34 -27
View File
@@ -906,35 +906,42 @@ StringMap CompilerStack::loadMissingSources(SourceUnit const& _ast, std::string
{
solAssert(m_stackState < ParsingPerformed, "");
StringMap newSources;
for (auto const& node: _ast.nodes())
if (ImportDirective const* import = dynamic_cast<ImportDirective*>(node.get()))
{
solAssert(!import->path().empty(), "Import path cannot be empty.");
string importPath = util::absolutePath(import->path(), _sourcePath);
// The current value of `path` is the absolute path as seen from this source file.
// We first have to apply remappings before we can store the actual absolute path
// as seen globally.
importPath = applyRemapping(importPath, _sourcePath);
import->annotation().absolutePath = importPath;
if (m_sources.count(importPath) || newSources.count(importPath))
continue;
ReadCallback::Result result{false, string("File not supplied initially.")};
if (m_readFile)
result = m_readFile(ReadCallback::kindString(ReadCallback::Kind::ReadFile), importPath);
if (result.success)
newSources[importPath] = result.responseOrErrorMessage;
else
try
{
for (auto const& node: _ast.nodes())
if (ImportDirective const* import = dynamic_cast<ImportDirective*>(node.get()))
{
m_errorReporter.parserError(
import->location(),
string("Source \"" + importPath + "\" not found: " + result.responseOrErrorMessage)
);
continue;
solAssert(!import->path().empty(), "Import path cannot be empty.");
string importPath = util::absolutePath(import->path(), _sourcePath);
// The current value of `path` is the absolute path as seen from this source file.
// We first have to apply remappings before we can store the actual absolute path
// as seen globally.
importPath = applyRemapping(importPath, _sourcePath);
import->annotation().absolutePath = importPath;
if (m_sources.count(importPath) || newSources.count(importPath))
continue;
ReadCallback::Result result{false, string("File not supplied initially.")};
if (m_readFile)
result = m_readFile(ReadCallback::kindString(ReadCallback::Kind::ReadFile), importPath);
if (result.success)
newSources[importPath] = result.responseOrErrorMessage;
else
{
m_errorReporter.parserError(
import->location(),
string("Source \"" + importPath + "\" not found: " + result.responseOrErrorMessage)
);
continue;
}
}
}
}
catch (FatalError const&)
{
solAssert(m_errorReporter.hasErrors(), "");
}
return newSources;
}