mirror of
https://github.com/Dummi26/mers.git
synced 2026-01-19 16:24:42 +01:00
add warning to if-statement in check mode
warning is shown if the condition of an if statement can never be true or false, and the user used the check command. warnings are not shown when you use `mers run`.
This commit is contained in:
@@ -142,10 +142,11 @@ pub struct CheckLocal {
|
||||
>,
|
||||
>,
|
||||
}
|
||||
#[derive(Clone, Debug, Default)]
|
||||
#[derive(Clone, Default)]
|
||||
pub struct CheckLocalGlobalInfo {
|
||||
pub depth: usize,
|
||||
pub enable_hooks: bool,
|
||||
pub show_warnings: Option<Arc<dyn Fn(CheckError) + Send + Sync>>,
|
||||
/// ((results, byte_pos_in_src, deepest_statement))
|
||||
/// you only have to set `byte_pos_in_src`. `deepest` is used internally.
|
||||
/// These values should be initialized to `(vec![], _, 0)`, but `0` can be replaced by a minimum statement depth, i.e. `2` to exclude the outer scope (which has depth `1`).
|
||||
@@ -160,6 +161,22 @@ pub struct CheckLocalGlobalInfo {
|
||||
>,
|
||||
pub unused_try_statements: Arc<Mutex<Vec<(SourceRange, Vec<Option<SourceRange>>)>>>,
|
||||
}
|
||||
impl CheckLocalGlobalInfo {
|
||||
pub fn show_warnings_to_stderr(&mut self) {
|
||||
self.show_warnings = Some(Arc::new(|e| {
|
||||
#[cfg(feature = "ecolor-term")]
|
||||
let theme = crate::errors::themes::TermDefaultTheme;
|
||||
#[cfg(not(feature = "ecolor-term"))]
|
||||
let theme = crate::errors::themes::NoTheme;
|
||||
eprintln!("{}", e.display(theme));
|
||||
}));
|
||||
}
|
||||
}
|
||||
impl Debug for CheckLocalGlobalInfo {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "CheckLocalGlobalInfo {{ depth: {}, enable_hooks: {}, show_warnings: {}, unused_try_statements: {} }}", self.depth, self.enable_hooks, self.show_warnings.is_some(), self.unused_try_statements.lock().unwrap().len())
|
||||
}
|
||||
}
|
||||
impl Debug for CheckLocal {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "CheckLocal {:?}, {:?}", self.vars, self.types.keys())
|
||||
|
||||
Reference in New Issue
Block a user