Add diagnostic codes to type-check warnings.

This commit is contained in:
KtorZ 2023-01-20 12:27:48 +01:00
parent e0046eea2b
commit 61be8ca73e
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
2 changed files with 18 additions and 2 deletions

View File

@ -1424,6 +1424,7 @@ impl Diagnostic for Error {
pub enum Warning { pub enum Warning {
#[error("I found a todo left in the code.\n")] #[error("I found a todo left in the code.\n")]
#[diagnostic(help("You probably want to replace that one with real code... eventually."))] #[diagnostic(help("You probably want to replace that one with real code... eventually."))]
#[diagnostic(code("todo"))]
Todo { Todo {
kind: TodoKind, kind: TodoKind,
#[label] #[label]
@ -1437,18 +1438,21 @@ pub enum Warning {
#[diagnostic(help( #[diagnostic(help(
"You can use the '_' symbol should you want to explicitly discard a result." "You can use the '_' symbol should you want to explicitly discard a result."
))] ))]
#[diagnostic(code("implicit_discard"))]
ImplicitlyDiscardedResult { ImplicitlyDiscardedResult {
#[label] #[label]
location: Span, location: Span,
}, },
#[error("I found a literal that is unused.\n")] #[error("I found a literal that is unused.\n")]
#[diagnostic(code("unused::literal"))]
UnusedLiteral { UnusedLiteral {
#[label] #[label]
location: Span, location: Span,
}, },
#[error("I found a public definition in a validator module.\nDefinitions in validator modules do not need to be public.\n")] #[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 { PubInValidatorModule {
#[label] #[label]
location: Span, location: Span,
@ -1456,6 +1460,7 @@ pub enum Warning {
#[error("I found a record update with no fields; effectively updating nothing.\n")] #[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(url("https://aiken-lang.org/language-tour/custom-types#record-updates"))]
#[diagnostic(code("record_update::no_fields"))]
NoFieldsRecordUpdate { NoFieldsRecordUpdate {
#[label] #[label]
location: Span, location: Span,
@ -1463,12 +1468,14 @@ pub enum Warning {
#[error("I found a record update using all fields; thus redundant.\n")] #[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(url("https://aiken-lang.org/language-tour/custom-types#record-updates"))]
#[diagnostic(code("record_update::all_fields"))]
AllFieldsRecordUpdate { AllFieldsRecordUpdate {
#[label] #[label]
location: Span, location: Span,
}, },
#[error("I discovered an unused type: '{}'.\n", name.purple())] #[error("I discovered an unused type: '{}'.\n", name.purple())]
#[diagnostic(code("unused::type"))]
UnusedType { UnusedType {
#[label] #[label]
location: Span, location: Span,
@ -1480,6 +1487,7 @@ pub enum Warning {
#[diagnostic(help( #[diagnostic(help(
"No big deal, but you might want to remove it to get rid of that warning." "No big deal, but you might want to remove it to get rid of that warning."
))] ))]
#[diagnostic(code("unused::constructor"))]
UnusedConstructor { UnusedConstructor {
#[label] #[label]
location: Span, location: Span,
@ -1491,6 +1499,7 @@ pub enum Warning {
#[diagnostic(help( #[diagnostic(help(
"No big deal, but you might want to remove it to get rid of that warning." "No big deal, but you might want to remove it to get rid of that warning."
))] ))]
#[diagnostic(code("unused:import::value"))]
UnusedImportedValue { UnusedImportedValue {
#[label] #[label]
location: Span, location: Span,
@ -1501,6 +1510,7 @@ pub enum Warning {
#[diagnostic(help( #[diagnostic(help(
"No big deal, but you might want to remove it to get rid of that warning." "No big deal, but you might want to remove it to get rid of that warning."
))] ))]
#[diagnostic(code("unused::import::module"))]
UnusedImportedModule { UnusedImportedModule {
#[label] #[label]
location: Span, location: Span,
@ -1513,6 +1523,7 @@ pub enum Warning {
Otherwise, you might want to get rid of it altogether." Otherwise, you might want to get rid of it altogether."
, keyword_pub = "pub".bright_blue() , keyword_pub = "pub".bright_blue()
))] ))]
#[diagnostic(code("unused::constant"))]
UnusedPrivateModuleConstant { UnusedPrivateModuleConstant {
#[label] #[label]
location: Span, location: Span,
@ -1525,6 +1536,7 @@ pub enum Warning {
Otherwise, you might want to get rid of it altogether." Otherwise, you might want to get rid of it altogether."
, keyword_pub = "pub".bright_blue() , keyword_pub = "pub".bright_blue()
))] ))]
#[diagnostic(code("unused::function"))]
UnusedPrivateFunction { UnusedPrivateFunction {
#[label] #[label]
location: Span, location: Span,
@ -1535,6 +1547,7 @@ pub enum Warning {
#[diagnostic(help( #[diagnostic(help(
"No big deal, but you might want to remove it to get rid of that warning." "No big deal, but you might want to remove it to get rid of that warning."
))] ))]
#[diagnostic(code("unused::variable"))]
UnusedVariable { UnusedVariable {
#[label] #[label]
location: Span, location: Span,

View File

@ -254,7 +254,7 @@ impl Diagnostic for Error {
Error::List(_) => None, Error::List(_) => None,
Error::Parse { .. } => Some(Box::new("aiken::parser")), Error::Parse { .. } => Some(Box::new("aiken::parser")),
Error::Type { error, .. } => Some(Box::new(format!( Error::Type { error, .. } => Some(Box::new(format!(
"err::aiken::check{}", "aiken::check{}",
error.code().map(|s| format!("::{s}")).unwrap_or_default() error.code().map(|s| format!("::{s}")).unwrap_or_default()
))), ))),
Error::StandardIo(_) => None, Error::StandardIo(_) => None,
@ -445,7 +445,10 @@ impl Diagnostic for Warning {
fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>> { fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
match self { 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::NoValidators => Some(Box::new("aiken::check")),
Warning::DependencyAlreadyExists { .. } => { Warning::DependencyAlreadyExists { .. } => {
Some(Box::new("aiken::packages::already_exists")) Some(Box::new("aiken::packages::already_exists"))