Skip to main content

crisp_typeck/
warning.rs

1//! Typeck warnings (non-fatal).
2
3use crisp_ast::Span;
4use thiserror::Error;
5
6#[derive(Debug, Clone, Error)]
7pub enum TypeWarning {
8    #[error(
9        "[W0087] converting `int` to `float` may lose precision above 2^53; write `as float` to silence"
10    )]
11    IntToFloat { span: Span },
12}
13
14impl TypeWarning {
15    pub fn code(&self) -> &'static str {
16        match self {
17            Self::IntToFloat { .. } => "W0087",
18        }
19    }
20
21    pub fn span(&self) -> Span {
22        match self {
23            Self::IntToFloat { span } => *span,
24        }
25    }
26}
27
28#[cfg(test)]
29mod tests {
30    use super::*;
31
32    #[test]
33    fn w0087_code() {
34        let w = TypeWarning::IntToFloat {
35            span: Span::new(0, 1),
36        };
37        assert_eq!(w.code(), "W0087");
38        assert!(w.to_string().contains("W0087"));
39    }
40}