diff --git a/crates/aiken-lang/src/error/mod.rs b/crates/aiken-lang/src/error/mod.rs new file mode 100644 index 00000000..30b902c3 --- /dev/null +++ b/crates/aiken-lang/src/error/mod.rs @@ -0,0 +1,3 @@ +pub trait ExtraData { + fn extra_data(&self) -> Option; +} diff --git a/crates/aiken-lang/src/lib.rs b/crates/aiken-lang/src/lib.rs index 3b4eb8de..3e7dc7cc 100644 --- a/crates/aiken-lang/src/lib.rs +++ b/crates/aiken-lang/src/lib.rs @@ -5,6 +5,7 @@ use std::sync::{ pub mod ast; pub mod builtins; +pub mod error; pub mod expr; pub mod format; pub mod gen_uplc; diff --git a/crates/aiken-lang/src/tipo/error.rs b/crates/aiken-lang/src/tipo/error.rs index 396da272..5c695d20 100644 --- a/crates/aiken-lang/src/tipo/error.rs +++ b/crates/aiken-lang/src/tipo/error.rs @@ -1,4 +1,5 @@ use super::Type; +use crate::error::ExtraData; use crate::{ ast::{Annotation, BinOp, CallArg, LogicalOpChainKind, Span, UntypedPattern}, expr::{self, UntypedExpr}, @@ -922,6 +923,63 @@ The best thing to do from here is to remove it."#))] }, } +impl ExtraData for Error { + fn extra_data(&self) -> Option { + match self { + Error::CastDataNoAnn { .. } + | Error::CouldNotUnify { .. } + | Error::CyclicTypeDefinitions { .. } + | Error::DuplicateArgument { .. } + | Error::DuplicateConstName { .. } + | Error::DuplicateField { .. } + | Error::DuplicateImport { .. } + | Error::DuplicateName { .. } + | Error::DuplicateTypeName { .. } + | Error::DuplicateVarInPattern { .. } + | Error::ExtraVarInAlternativePattern { .. } + | Error::FunctionTypeInData { .. } + | Error::ImplicitlyDiscardedExpression { .. } + | Error::IncorrectFieldsArity { .. } + | Error::IncorrectFunctionCallArity { .. } + | Error::IncorrectPatternArity { .. } + | Error::IncorrectTupleArity { .. } + | Error::IncorrectTypeArity { .. } + | Error::IncorrectValidatorArity { .. } + | Error::KeywordInModuleName { .. } + | Error::LastExpressionIsAssignment { .. } + | Error::LogicalOpChainMissingExpr { .. } + | Error::MissingVarInAlternativePattern { .. } + | Error::MultiValidatorEqualArgs { .. } + | Error::NonLocalClauseGuardVariable { .. } + | Error::NotATuple { .. } + | Error::NotExhaustivePatternMatch { .. } + | Error::NotFn { .. } + | Error::PositionalArgumentAfterLabeled { .. } + | Error::PrivateTypeLeak { .. } + | Error::RecordAccessUnknownType { .. } + | Error::RecordUpdateInvalidConstructor { .. } + | Error::RecursiveType { .. } + | Error::RedundantMatchClause { .. } + | Error::TupleIndexOutOfBound { .. } + | Error::UnexpectedLabeledArg { .. } + | Error::UnexpectedLabeledArgInPattern { .. } + | Error::UnknownLabels { .. } + | Error::UnknownModule { .. } + | Error::UnknownModuleField { .. } + | Error::UnknownModuleType { .. } + | Error::UnknownModuleValue { .. } + | Error::UnknownRecordField { .. } + | Error::UnknownType { .. } + | Error::UnknownTypeConstructor { .. } + | Error::UnnecessarySpreadOperator { .. } + | Error::UpdateMultiConstructorType { .. } + | Error::ValidatorImported { .. } + | Error::ValidatorMustReturnBool { .. } => None, + Error::UnknownVariable { name, .. } => Some(name.clone()), + } + } +} + impl Error { pub fn call_situation(mut self) -> Self { if let Error::UnknownRecordField { @@ -1522,6 +1580,30 @@ pub enum Warning { }, } +impl ExtraData for Warning { + fn extra_data(&self) -> Option { + match self { + Warning::AllFieldsRecordUpdate { .. } + | Warning::ImplicitlyDiscardedResult { .. } + | Warning::NoFieldsRecordUpdate { .. } + | Warning::PubInValidatorModule { .. } + | Warning::SingleConstructorExpect { .. } + | Warning::SingleWhenClause { .. } + | Warning::Todo { .. } + | Warning::UnexpectedTypeHole { .. } + | Warning::UnusedConstructor { .. } + | Warning::UnusedImportedModule { .. } + | Warning::UnusedImportedValue { .. } + | Warning::UnusedPrivateFunction { .. } + | Warning::UnusedPrivateModuleConstant { .. } + | Warning::UnusedType { .. } + | Warning::UnusedVariable { .. } + | Warning::Utf8ByteArrayIsValidHexString { .. } + | Warning::ValidatorInLibraryModule { .. } => None, + } + } +} + #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum UnifyErrorSituation { /// Clauses in a case expression were found to return different types. diff --git a/crates/aiken-project/src/error.rs b/crates/aiken-project/src/error.rs index f657c83b..0dcd2653 100644 --- a/crates/aiken-project/src/error.rs +++ b/crates/aiken-project/src/error.rs @@ -4,6 +4,7 @@ use crate::{ }; use aiken_lang::{ ast::{self, BinOp, Span}, + error::ExtraData, parser::error::ParseError, tipo, }; @@ -172,6 +173,34 @@ impl From for Vec { } } +impl ExtraData for Error { + fn extra_data(&self) -> Option { + match self { + Error::DuplicateModule { .. } => None, + Error::FileIo { .. } => None, + Error::Format { .. } => None, + Error::StandardIo { .. } => None, + Error::Blueprint { .. } => None, + Error::MissingManifest { .. } => None, + Error::TomlLoading { .. } => None, + Error::ImportCycle { .. } => None, + Error::Parse { .. } => None, + Error::Type { error, .. } => error.extra_data(), + Error::TestFailure { .. } => None, + Error::Http { .. } => None, + Error::ZipExtract { .. } => None, + Error::JoinError { .. } => None, + Error::UnknownPackageVersion { .. } => None, + Error::UnableToResolvePackage { .. } => None, + Error::Json { .. } => None, + Error::MalformedStakeAddress { .. } => None, + Error::NoValidatorNotFound { .. } => None, + Error::MoreThanOneValidatorFound { .. } => None, + Error::Module { .. } => None, + } + } +} + pub trait GetSource { fn path(&self) -> Option; fn src(&self) -> Option; @@ -481,6 +510,16 @@ pub enum Warning { DependencyAlreadyExists { name: PackageName }, } +impl ExtraData for Warning { + fn extra_data(&self) -> Option { + match self { + Warning::NoValidators { .. } => None, + Warning::DependencyAlreadyExists { .. } => None, + Warning::Type { warning, .. } => warning.extra_data(), + } + } +} + impl GetSource for Warning { fn path(&self) -> Option { match self {