From 21a4adea3e3b205b627ada370f4fbdc00ec0574e Mon Sep 17 00:00:00 2001 From: Bjerg Date: Fri, 7 Jan 2022 15:53:36 +0100 Subject: [PATCH] Check for warnings after compilation (#772) * Check for warnings after compilation * Always catch errors first --- ethers-solc/src/artifacts.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/ethers-solc/src/artifacts.rs b/ethers-solc/src/artifacts.rs index 615e9628..7c916f4d 100644 --- a/ethers-solc/src/artifacts.rs +++ b/ethers-solc/src/artifacts.rs @@ -531,11 +531,16 @@ pub struct CompilerOutput { } impl CompilerOutput { - /// Whether the output contains an compiler error + /// Whether the output contains a compiler error pub fn has_error(&self) -> bool { self.errors.iter().any(|err| err.severity.is_error()) } + /// Whether the output contains a compiler warning + pub fn has_warning(&self) -> bool { + self.errors.iter().any(|err| err.severity.is_warning()) + } + pub fn diagnostics<'a>(&'a self, ignored_error_codes: &'a [u64]) -> OutputDiagnostics { OutputDiagnostics { errors: &self.errors, ignored_error_codes } } @@ -687,11 +692,20 @@ impl<'a> OutputDiagnostics<'a> { pub fn has_error(&self) -> bool { self.errors.iter().any(|err| err.severity.is_error()) } + + /// Returns true if there is at least one warning + pub fn has_warning(&self) -> bool { + self.errors.iter().any(|err| err.severity.is_warning()) + } } impl<'a> fmt::Display for OutputDiagnostics<'a> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - if !self.has_error() { + if self.has_error() { + f.write_str("Compiler run failed")?; + } else if self.has_warning() { + f.write_str("Compiler run successful (with warnings)")?; + } else { f.write_str("Compiler run successful")?; } for err in self.errors {