Skip to content

Commit

Permalink
Disallowed --error-recovery in Standard json, Assembly and Linker inp…
Browse files Browse the repository at this point in the history
…ut modes
  • Loading branch information
Midhun07 committed Oct 6, 2021
1 parent a709216 commit 8b8140b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
17 changes: 17 additions & 0 deletions solc/CommandLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,23 @@ bool CommandLineParser::processArgs()
m_options.output.stopAfter = CompilerStack::State::Parsed;
}

map<string, set<InputMode>> validOptionInputModeCombinations = {
{g_strErrorRecovery, {InputMode::Compiler, InputMode::CompilerWithASTImport}},
{g_strExperimentalViaIR, {InputMode::Compiler, InputMode::CompilerWithASTImport}},
};
string invalidOptions;
for (auto const& [optionName, inputModes]: validOptionInputModeCombinations)
{
if (m_args.count(optionName) > 0 && inputModes.count(m_options.input.mode) == 0)
invalidOptions.append("--" + optionName + " ");
}

if (!invalidOptions.empty())
{
serr() << "The option " << invalidOptions << "is not supported in the current mode." << endl;
return false;
}

if (!parseInputPathsAndRemappings())
return false;

Expand Down
37 changes: 22 additions & 15 deletions test/solc/CommandLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ BOOST_AUTO_TEST_CASE(assembly_mode_options)
"--include-path=/home/user/include",
"--allow-paths=/tmp,/home,project,../contracts",
"--ignore-missing",
"--error-recovery", // Ignored in assembly mode
"--overwrite",
"--evm-version=spuriousDragon",
"--revert-strings=strip", // Accepted but has no effect in assembly mode
Expand Down Expand Up @@ -361,7 +360,6 @@ BOOST_AUTO_TEST_CASE(standard_json_mode_options)
"--include-path=/home/user/include",
"--allow-paths=/tmp,/home,project,../contracts",
"--ignore-missing",
"--error-recovery", // Ignored in Standard JSON mode
"--output-dir=/tmp/out", // Accepted but has no effect in Standard JSON mode
"--overwrite", // Accepted but has no effect in Standard JSON mode
"--evm-version=spuriousDragon", // Ignored in Standard JSON mode
Expand Down Expand Up @@ -427,7 +425,7 @@ BOOST_AUTO_TEST_CASE(standard_json_mode_options)
BOOST_TEST(parsedOptions.value() == expectedOptions);
}

BOOST_AUTO_TEST_CASE(experimental_via_ir_invalid_input_modes)
BOOST_AUTO_TEST_CASE(invalis_options_input_modes_combinations)
{
static array<string, 5> const inputModeOptions = {
"--assemble",
Expand All @@ -436,20 +434,29 @@ BOOST_AUTO_TEST_CASE(experimental_via_ir_invalid_input_modes)
"--standard-json",
"--link",
};
for (string const& inputModeOption: inputModeOptions)

static array<string, 2> const invalidOptions = {
"--error-recovery",
"--experimental-via-ir",
};

for (string const& invalidOption: invalidOptions)
{
stringstream sout, serr;
vector<string> commandLine = {
"solc",
"--experimental-via-ir",
"file",
inputModeOption,
};
optional<CommandLineOptions> parsedOptions = parseCommandLine(commandLine, sout, serr);
for (string const& inputModeOption: inputModeOptions)
{
stringstream sout, serr;
vector<string> commandLine = {
"solc",
invalidOption,
"file",
inputModeOption,
};
optional<CommandLineOptions> parsedOptions = parseCommandLine(commandLine, sout, serr);

BOOST_TEST(sout.str() == "");
BOOST_TEST(serr.str() == "The option --experimental-via-ir is only supported in the compiler mode.\n");
BOOST_REQUIRE(!parsedOptions.has_value());
BOOST_TEST(sout.str() == "");
BOOST_TEST(serr.str() == "The option " + invalidOption + " is not supported in the current mode.\n");
BOOST_REQUIRE(!parsedOptions.has_value());
}
}
}

Expand Down

0 comments on commit 8b8140b

Please sign in to comment.