From 3f3f8adcb81d627024b22ebd1eb18e914c457a48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Mon, 29 Jun 2020 15:11:33 +0200 Subject: [PATCH] CommandLineInterface: In error message about options disallowed in assembly mode only include the names of actually used options --- solc/CommandLineInterface.cpp | 10 ++++++++-- .../strict_asm_invalid_option_optimize_yul/args | 1 + .../strict_asm_invalid_option_optimize_yul/err | 1 + .../strict_asm_invalid_option_optimize_yul/exit | 1 + .../strict_asm_invalid_option_optimize_yul/input.yul | 3 +++ .../strict_asm_invalid_option_output_dir/err | 2 +- 6 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 test/cmdlineTests/strict_asm_invalid_option_optimize_yul/args create mode 100644 test/cmdlineTests/strict_asm_invalid_option_optimize_yul/err create mode 100644 test/cmdlineTests/strict_asm_invalid_option_optimize_yul/exit create mode 100644 test/cmdlineTests/strict_asm_invalid_option_optimize_yul/input.yul diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index bbf0eeb53..3bd374676 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -59,6 +59,7 @@ #include #include #include +#include #include #ifdef _WIN32 // windows @@ -1200,9 +1201,14 @@ bool CommandLineInterface::processInput() }; if (countEnabledOptions(nonAssemblyModeOptions) >= 1) { + auto optionEnabled = [&](string const& name){ return m_args.count(name) > 0; }; + auto enabledOptions = boost::copy_range>(nonAssemblyModeOptions | boost::adaptors::filtered(optionEnabled)); + serr() << "The following options are invalid in assembly mode: "; - serr() << joinOptionNames(nonAssemblyModeOptions) << ". "; - serr() << "Optimization is disabled by default and can be enabled with --" << g_argOptimize << "." << endl; + serr() << joinOptionNames(enabledOptions) << "."; + if (m_args.count(g_strOptimizeYul) || m_args.count(g_strNoOptimizeYul)) + serr() << " Optimization is disabled by default and can be enabled with --" << g_argOptimize << "." << endl; + serr() << endl; return false; } diff --git a/test/cmdlineTests/strict_asm_invalid_option_optimize_yul/args b/test/cmdlineTests/strict_asm_invalid_option_optimize_yul/args new file mode 100644 index 000000000..827d99829 --- /dev/null +++ b/test/cmdlineTests/strict_asm_invalid_option_optimize_yul/args @@ -0,0 +1 @@ +--strict-assembly --optimize-yul diff --git a/test/cmdlineTests/strict_asm_invalid_option_optimize_yul/err b/test/cmdlineTests/strict_asm_invalid_option_optimize_yul/err new file mode 100644 index 000000000..a6378a665 --- /dev/null +++ b/test/cmdlineTests/strict_asm_invalid_option_optimize_yul/err @@ -0,0 +1 @@ +The following options are invalid in assembly mode: --optimize-yul. Optimization is disabled by default and can be enabled with --optimize. diff --git a/test/cmdlineTests/strict_asm_invalid_option_optimize_yul/exit b/test/cmdlineTests/strict_asm_invalid_option_optimize_yul/exit new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/test/cmdlineTests/strict_asm_invalid_option_optimize_yul/exit @@ -0,0 +1 @@ +1 diff --git a/test/cmdlineTests/strict_asm_invalid_option_optimize_yul/input.yul b/test/cmdlineTests/strict_asm_invalid_option_optimize_yul/input.yul new file mode 100644 index 000000000..f21cd2b7e --- /dev/null +++ b/test/cmdlineTests/strict_asm_invalid_option_optimize_yul/input.yul @@ -0,0 +1,3 @@ +{ + sstore(0, 1) +} diff --git a/test/cmdlineTests/strict_asm_invalid_option_output_dir/err b/test/cmdlineTests/strict_asm_invalid_option_output_dir/err index a9b56e9c7..738a37b29 100644 --- a/test/cmdlineTests/strict_asm_invalid_option_output_dir/err +++ b/test/cmdlineTests/strict_asm_invalid_option_output_dir/err @@ -1 +1 @@ -The following options are invalid in assembly mode: --output-dir, --gas, --combined-json, --optimize-yul, --no-optimize-yul. Optimization is disabled by default and can be enabled with --optimize. +The following options are invalid in assembly mode: --output-dir.