From 61be8ca73e77e5160251181724bc4c5aa2b61d99 Mon Sep 17 00:00:00 2001 From: KtorZ Date: Fri, 20 Jan 2023 12:27:48 +0100 Subject: [PATCH] Add diagnostic codes to type-check warnings. --- crates/aiken-lang/src/tipo/error.rs | 13 +++++++++++++ crates/aiken-project/src/error.rs | 7 +++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/aiken-lang/src/tipo/error.rs b/crates/aiken-lang/src/tipo/error.rs index bacfe2cc..d2c63d1c 100644 --- a/crates/aiken-lang/src/tipo/error.rs +++ b/crates/aiken-lang/src/tipo/error.rs @@ -1424,6 +1424,7 @@ impl Diagnostic for Error { pub enum Warning { #[error("I found a todo left in the code.\n")] #[diagnostic(help("You probably want to replace that one with real code... eventually."))] + #[diagnostic(code("todo"))] Todo { kind: TodoKind, #[label] @@ -1437,18 +1438,21 @@ pub enum Warning { #[diagnostic(help( "You can use the '_' symbol should you want to explicitly discard a result." ))] + #[diagnostic(code("implicit_discard"))] ImplicitlyDiscardedResult { #[label] location: Span, }, #[error("I found a literal that is unused.\n")] + #[diagnostic(code("unused::literal"))] UnusedLiteral { #[label] location: Span, }, #[error("I found a public definition in a validator module.\nDefinitions in validator modules do not need to be public.\n")] + #[diagnostic(code("redundant::pub"))] PubInValidatorModule { #[label] location: Span, @@ -1456,6 +1460,7 @@ pub enum Warning { #[error("I found a record update with no fields; effectively updating nothing.\n")] #[diagnostic(url("https://aiken-lang.org/language-tour/custom-types#record-updates"))] + #[diagnostic(code("record_update::no_fields"))] NoFieldsRecordUpdate { #[label] location: Span, @@ -1463,12 +1468,14 @@ pub enum Warning { #[error("I found a record update using all fields; thus redundant.\n")] #[diagnostic(url("https://aiken-lang.org/language-tour/custom-types#record-updates"))] + #[diagnostic(code("record_update::all_fields"))] AllFieldsRecordUpdate { #[label] location: Span, }, #[error("I discovered an unused type: '{}'.\n", name.purple())] + #[diagnostic(code("unused::type"))] UnusedType { #[label] location: Span, @@ -1480,6 +1487,7 @@ pub enum Warning { #[diagnostic(help( "No big deal, but you might want to remove it to get rid of that warning." ))] + #[diagnostic(code("unused::constructor"))] UnusedConstructor { #[label] location: Span, @@ -1491,6 +1499,7 @@ pub enum Warning { #[diagnostic(help( "No big deal, but you might want to remove it to get rid of that warning." ))] + #[diagnostic(code("unused:import::value"))] UnusedImportedValue { #[label] location: Span, @@ -1501,6 +1510,7 @@ pub enum Warning { #[diagnostic(help( "No big deal, but you might want to remove it to get rid of that warning." ))] + #[diagnostic(code("unused::import::module"))] UnusedImportedModule { #[label] location: Span, @@ -1513,6 +1523,7 @@ pub enum Warning { Otherwise, you might want to get rid of it altogether." , keyword_pub = "pub".bright_blue() ))] + #[diagnostic(code("unused::constant"))] UnusedPrivateModuleConstant { #[label] location: Span, @@ -1525,6 +1536,7 @@ pub enum Warning { Otherwise, you might want to get rid of it altogether." , keyword_pub = "pub".bright_blue() ))] + #[diagnostic(code("unused::function"))] UnusedPrivateFunction { #[label] location: Span, @@ -1535,6 +1547,7 @@ pub enum Warning { #[diagnostic(help( "No big deal, but you might want to remove it to get rid of that warning." ))] + #[diagnostic(code("unused::variable"))] UnusedVariable { #[label] location: Span, diff --git a/crates/aiken-project/src/error.rs b/crates/aiken-project/src/error.rs index 861c2038..05eff097 100644 --- a/crates/aiken-project/src/error.rs +++ b/crates/aiken-project/src/error.rs @@ -254,7 +254,7 @@ impl Diagnostic for Error { Error::List(_) => None, Error::Parse { .. } => Some(Box::new("aiken::parser")), Error::Type { error, .. } => Some(Box::new(format!( - "err::aiken::check{}", + "aiken::check{}", error.code().map(|s| format!("::{s}")).unwrap_or_default() ))), Error::StandardIo(_) => None, @@ -445,7 +445,10 @@ impl Diagnostic for Warning { fn code<'a>(&'a self) -> Option> { match self { - Warning::Type { .. } => Some(Box::new("aiken::check")), + Warning::Type { warning, .. } => Some(Box::new(format!( + "aiken::check{}", + warning.code().map(|s| format!("::{s}")).unwrap_or_default() + ))), Warning::NoValidators => Some(Box::new("aiken::check")), Warning::DependencyAlreadyExists { .. } => { Some(Box::new("aiken::packages::already_exists"))