mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #11909 from Midhun07/develop
Template code for disallowing options in input modes that do not support them (handles `--error-recovery`)
This commit is contained in:
commit
72b88dabca
@ -17,6 +17,7 @@ Bugfixes:
|
|||||||
* Commandline Interface: Fix extra newline character being appended to sources passed through standard input, affecting their hashes.
|
* Commandline Interface: Fix extra newline character being appended to sources passed through standard input, affecting their hashes.
|
||||||
* Commandline Interface: Report output selection options unsupported by the selected input mode instead of ignoring them.
|
* Commandline Interface: Report output selection options unsupported by the selected input mode instead of ignoring them.
|
||||||
* Commandline Interface: Don't return zero exit code when writing linked files to disk fails.
|
* Commandline Interface: Don't return zero exit code when writing linked files to disk fails.
|
||||||
|
* Commandline Interface: Disallow ``--error-recovery`` option outside of the compiler mode.
|
||||||
* SMTChecker: Fix internal error in magic type access (``block``, ``msg``, ``tx``).
|
* SMTChecker: Fix internal error in magic type access (``block``, ``msg``, ``tx``).
|
||||||
* TypeChecker: Fix internal error when using user defined value types in public library functions.
|
* TypeChecker: Fix internal error when using user defined value types in public library functions.
|
||||||
* Yul IR Generator: Do not output empty switches/if-bodies for empty contracts.
|
* Yul IR Generator: Do not output empty switches/if-bodies for empty contracts.
|
||||||
|
@ -898,13 +898,21 @@ bool CommandLineParser::processArgs()
|
|||||||
else
|
else
|
||||||
m_options.input.mode = InputMode::Compiler;
|
m_options.input.mode = InputMode::Compiler;
|
||||||
|
|
||||||
if (
|
map<string, set<InputMode>> validOptionInputModeCombinations = {
|
||||||
m_args.count(g_strExperimentalViaIR) > 0 &&
|
// TODO: This should eventually contain all options.
|
||||||
m_options.input.mode != InputMode::Compiler &&
|
{g_strErrorRecovery, {InputMode::Compiler, InputMode::CompilerWithASTImport}},
|
||||||
m_options.input.mode != InputMode::CompilerWithASTImport
|
{g_strExperimentalViaIR, {InputMode::Compiler, InputMode::CompilerWithASTImport}},
|
||||||
)
|
};
|
||||||
|
vector<string> invalidOptionsForCurrentInputMode;
|
||||||
|
for (auto const& [optionName, inputModes]: validOptionInputModeCombinations)
|
||||||
{
|
{
|
||||||
serr() << "The option --" << g_strExperimentalViaIR << " is only supported in the compiler mode." << endl;
|
if (m_args.count(optionName) > 0 && inputModes.count(m_options.input.mode) == 0)
|
||||||
|
invalidOptionsForCurrentInputMode.push_back(optionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!invalidOptionsForCurrentInputMode.empty())
|
||||||
|
{
|
||||||
|
serr() << "The following options are not supported in the current input mode: " << joinOptionNames(invalidOptionsForCurrentInputMode) << endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,7 +267,6 @@ BOOST_AUTO_TEST_CASE(assembly_mode_options)
|
|||||||
"--include-path=/home/user/include",
|
"--include-path=/home/user/include",
|
||||||
"--allow-paths=/tmp,/home,project,../contracts",
|
"--allow-paths=/tmp,/home,project,../contracts",
|
||||||
"--ignore-missing",
|
"--ignore-missing",
|
||||||
"--error-recovery", // Ignored in assembly mode
|
|
||||||
"--overwrite",
|
"--overwrite",
|
||||||
"--evm-version=spuriousDragon",
|
"--evm-version=spuriousDragon",
|
||||||
"--revert-strings=strip", // Accepted but has no effect in assembly mode
|
"--revert-strings=strip", // Accepted but has no effect in assembly mode
|
||||||
@ -356,7 +355,6 @@ BOOST_AUTO_TEST_CASE(standard_json_mode_options)
|
|||||||
"--include-path=/home/user/include",
|
"--include-path=/home/user/include",
|
||||||
"--allow-paths=/tmp,/home,project,../contracts",
|
"--allow-paths=/tmp,/home,project,../contracts",
|
||||||
"--ignore-missing",
|
"--ignore-missing",
|
||||||
"--error-recovery", // Ignored in Standard JSON mode
|
|
||||||
"--output-dir=/tmp/out", // Accepted but has no effect 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
|
"--overwrite", // Accepted but has no effect in Standard JSON mode
|
||||||
"--evm-version=spuriousDragon", // Ignored in Standard JSON mode
|
"--evm-version=spuriousDragon", // Ignored in Standard JSON mode
|
||||||
@ -413,30 +411,25 @@ BOOST_AUTO_TEST_CASE(standard_json_mode_options)
|
|||||||
BOOST_TEST(parsedOptions.value() == expectedOptions);
|
BOOST_TEST(parsedOptions.value() == expectedOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(experimental_via_ir_invalid_input_modes)
|
BOOST_AUTO_TEST_CASE(invalid_options_input_modes_combinations)
|
||||||
{
|
{
|
||||||
static array<string, 5> const inputModeOptions = {
|
map<string, vector<string>> invalidOptionInputModeCombinations = {
|
||||||
"--assemble",
|
// TODO: This should eventually contain all options.
|
||||||
"--yul",
|
{"--error-recovery", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
|
||||||
"--strict-assembly",
|
{"--experimental-via-ir", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}}
|
||||||
"--standard-json",
|
|
||||||
"--link",
|
|
||||||
};
|
};
|
||||||
for (string const& inputModeOption: inputModeOptions)
|
|
||||||
{
|
|
||||||
stringstream sout, serr;
|
|
||||||
vector<string> commandLine = {
|
|
||||||
"solc",
|
|
||||||
"--experimental-via-ir",
|
|
||||||
"file",
|
|
||||||
inputModeOption,
|
|
||||||
};
|
|
||||||
optional<CommandLineOptions> parsedOptions = parseCommandLine(commandLine, sout, serr);
|
|
||||||
|
|
||||||
BOOST_TEST(sout.str() == "");
|
for (auto const& [optionName, inputModes]: invalidOptionInputModeCombinations)
|
||||||
BOOST_TEST(serr.str() == "The option --experimental-via-ir is only supported in the compiler mode.\n");
|
for (string const& inputMode: inputModes)
|
||||||
BOOST_REQUIRE(!parsedOptions.has_value());
|
{
|
||||||
}
|
stringstream sout, serr;
|
||||||
|
vector<string> commandLine = {"solc", optionName, "file", inputMode};
|
||||||
|
optional<CommandLineOptions> parsedOptions = parseCommandLine(commandLine, sout, serr);
|
||||||
|
|
||||||
|
BOOST_TEST(sout.str() == "");
|
||||||
|
BOOST_TEST(serr.str() == "The following options are not supported in the current input mode: " + optionName + "\n");
|
||||||
|
BOOST_REQUIRE(!parsedOptions.has_value());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
Loading…
Reference in New Issue
Block a user