Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 25 additions & 28 deletions clarity-types/src/errors/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,38 +162,38 @@ pub enum CheckErrors {
// match errors
BadMatchOptionSyntax(Box<CheckErrors>),
BadMatchResponseSyntax(Box<CheckErrors>),
BadMatchInput(TypeSignature),
BadMatchInput(Box<TypeSignature>),

// list typing errors
UnknownListConstructionFailure,
ListTypesMustMatch,
ConstructedListTooLarge,

// simple type expectation mismatch
TypeError(TypeSignature, TypeSignature),
TypeLiteralError(TypeSignature, TypeSignature),
TypeValueError(TypeSignature, Value),
TypeError(Box<TypeSignature>, Box<TypeSignature>),
TypeLiteralError(Box<TypeSignature>, Box<TypeSignature>),
TypeValueError(Box<TypeSignature>, Box<Value>),

NoSuperType(TypeSignature, TypeSignature),
NoSuperType(Box<TypeSignature>, Box<TypeSignature>),
InvalidTypeDescription,
UnknownTypeName(String),

// union type mismatch
UnionTypeError(Vec<TypeSignature>, TypeSignature),
UnionTypeValueError(Vec<TypeSignature>, Value),
UnionTypeError(Vec<TypeSignature>, Box<TypeSignature>),
UnionTypeValueError(Vec<TypeSignature>, Box<Value>),

ExpectedLiteral,
ExpectedOptionalType(TypeSignature),
ExpectedResponseType(TypeSignature),
ExpectedOptionalOrResponseType(TypeSignature),
ExpectedOptionalValue(Value),
ExpectedResponseValue(Value),
ExpectedOptionalOrResponseValue(Value),
ExpectedOptionalType(Box<TypeSignature>),
ExpectedResponseType(Box<TypeSignature>),
ExpectedOptionalOrResponseType(Box<TypeSignature>),
ExpectedOptionalValue(Box<Value>),
ExpectedResponseValue(Box<Value>),
ExpectedOptionalOrResponseValue(Box<Value>),
CouldNotDetermineResponseOkType,
CouldNotDetermineResponseErrType,
CouldNotDetermineSerializationType,
UncheckedIntermediaryResponses,
ExpectedContractPrincipalValue(Value),
ExpectedContractPrincipalValue(Box<Value>),

CouldNotDetermineMatchTypes,
CouldNotDetermineType,
Expand All @@ -218,7 +218,7 @@ pub enum CheckErrors {

// tuples
BadTupleFieldName,
ExpectedTuple(TypeSignature),
ExpectedTuple(Box<TypeSignature>),
NoSuchTupleField(String, TupleTypeSignature),
EmptyTuplesNotAllowed,
BadTupleConstruction(String),
Expand All @@ -234,9 +234,9 @@ pub enum CheckErrors {
DefineFunctionBadSignature,
BadFunctionName,
BadMapTypeDefinition,
PublicFunctionMustReturnResponse(TypeSignature),
PublicFunctionMustReturnResponse(Box<TypeSignature>),
DefineVariableBadSignature,
ReturnTypesMustMatch(TypeSignature, TypeSignature),
ReturnTypesMustMatch(Box<TypeSignature>, Box<TypeSignature>),

CircularReference(Vec<String>),

Expand All @@ -246,7 +246,7 @@ pub enum CheckErrors {
PublicFunctionNotReadOnly(String, String),
ContractAlreadyExists(String),
ContractCallExpectName,
ExpectedCallableType(TypeSignature),
ExpectedCallableType(Box<TypeSignature>),

// get-block-info? errors
NoSuchBlockInfoProperty(String),
Expand All @@ -264,7 +264,7 @@ pub enum CheckErrors {
// expect a function, or applying a function to a list
NonFunctionApplication,
ExpectedListApplication,
ExpectedSequence(TypeSignature),
ExpectedSequence(Box<TypeSignature>),
MaxLengthOverflow,

// let syntax
Expand All @@ -281,9 +281,9 @@ pub enum CheckErrors {
RequiresAtLeastArguments(usize, usize),
RequiresAtMostArguments(usize, usize),
IncorrectArgumentCount(usize, usize),
IfArmsMustMatch(TypeSignature, TypeSignature),
MatchArmsMustMatch(TypeSignature, TypeSignature),
DefaultTypesMustMatch(TypeSignature, TypeSignature),
IfArmsMustMatch(Box<TypeSignature>, Box<TypeSignature>),
MatchArmsMustMatch(Box<TypeSignature>, Box<TypeSignature>),
DefaultTypesMustMatch(Box<TypeSignature>, Box<TypeSignature>),
TooManyExpressions,
IllegalOrUnknownFunctionApplication(String),
UnknownFunction(String),
Expand All @@ -301,7 +301,7 @@ pub enum CheckErrors {
UnexpectedTraitOrFieldReference,
TraitBasedContractCallInReadOnly,
ContractOfExpectsTrait,
IncompatibleTrait(TraitIdentifier, TraitIdentifier),
IncompatibleTrait(Box<TraitIdentifier>, Box<TraitIdentifier>),

// strings
InvalidCharactersDetected,
Expand All @@ -319,7 +319,7 @@ pub enum CheckErrors {

#[derive(Debug, PartialEq)]
pub struct CheckError {
pub err: CheckErrors,
pub err: Box<CheckErrors>,
pub expressions: Option<Vec<SymbolicExpression>>,
pub diagnostic: Diagnostic,
}
Expand All @@ -339,7 +339,7 @@ impl CheckError {
pub fn new(err: CheckErrors) -> CheckError {
let diagnostic = Diagnostic::err(&err);
CheckError {
err,
err: Box::new(err),
expressions: None,
diagnostic,
}
Expand Down Expand Up @@ -454,7 +454,6 @@ impl From<CheckErrors> for String {
}
}

#[allow(clippy::result_large_err)]
pub fn check_argument_count<T>(expected: usize, args: &[T]) -> Result<(), CheckErrors> {
if args.len() != expected {
Err(CheckErrors::IncorrectArgumentCount(expected, args.len()))
Expand All @@ -463,7 +462,6 @@ pub fn check_argument_count<T>(expected: usize, args: &[T]) -> Result<(), CheckE
}
}

#[allow(clippy::result_large_err)]
pub fn check_arguments_at_least<T>(expected: usize, args: &[T]) -> Result<(), CheckErrors> {
if args.len() < expected {
Err(CheckErrors::RequiresAtLeastArguments(expected, args.len()))
Expand All @@ -472,7 +470,6 @@ pub fn check_arguments_at_least<T>(expected: usize, args: &[T]) -> Result<(), Ch
}
}

#[allow(clippy::result_large_err)]
pub fn check_arguments_at_most<T>(expected: usize, args: &[T]) -> Result<(), CheckErrors> {
if args.len() > expected {
Err(CheckErrors::RequiresAtMostArguments(expected, args.len()))
Expand Down
6 changes: 3 additions & 3 deletions clarity-types/src/errors/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub enum ParseErrors {

#[derive(Debug, PartialEq)]
pub struct ParseError {
pub err: ParseErrors,
pub err: Box<ParseErrors>,
pub pre_expressions: Option<Vec<PreSymbolicExpression>>,
pub diagnostic: Diagnostic,
}
Expand All @@ -107,14 +107,14 @@ impl ParseError {
pub fn new(err: ParseErrors) -> ParseError {
let diagnostic = Diagnostic::err(&err);
ParseError {
err,
err: Box::new(err),
pre_expressions: None,
diagnostic,
}
}

pub fn rejectable(&self) -> bool {
matches!(self.err, ParseErrors::InterpreterFailure)
matches!(*self.err, ParseErrors::InterpreterFailure)
}

pub fn has_pre_expression(&self) -> bool {
Expand Down
20 changes: 10 additions & 10 deletions clarity-types/src/errors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub enum RuntimeErrorType {
// error in parsing types
ParseError(String),
// error in parsing the AST
ASTError(ParseError),
ASTError(Box<ParseError>),
MaxStackDepthReached,
MaxContextDepthReached,
BadTypeConstruction,
Expand All @@ -103,8 +103,8 @@ pub enum RuntimeErrorType {

#[derive(Debug, PartialEq)]
pub enum ShortReturnType {
ExpectedValue(Value),
AssertionFailed(Value),
ExpectedValue(Box<Value>),
AssertionFailed(Box<Value>),
}

pub type InterpreterResult<R> = Result<R, Error>;
Expand Down Expand Up @@ -165,11 +165,11 @@ impl error::Error for RuntimeErrorType {

impl From<ParseError> for Error {
fn from(err: ParseError) -> Self {
match &err.err {
match *err.err {
ParseErrors::InterpreterFailure => Error::from(InterpreterError::Expect(
"Unexpected interpreter failure during parsing".into(),
)),
_ => Error::from(RuntimeErrorType::ASTError(err)),
_ => Error::from(RuntimeErrorType::ASTError(Box::new(err))),
}
}
}
Expand Down Expand Up @@ -226,8 +226,8 @@ impl From<Error> for () {
impl From<ShortReturnType> for Value {
fn from(val: ShortReturnType) -> Self {
match val {
ShortReturnType::ExpectedValue(v) => v,
ShortReturnType::AssertionFailed(v) => v,
ShortReturnType::ExpectedValue(v) => *v,
ShortReturnType::AssertionFailed(v) => *v,
}
}
}
Expand All @@ -239,15 +239,15 @@ mod test {
#[test]
fn equality() {
assert_eq!(
Error::ShortReturn(ShortReturnType::ExpectedValue(Value::Bool(true))),
Error::ShortReturn(ShortReturnType::ExpectedValue(Value::Bool(true)))
Error::ShortReturn(ShortReturnType::ExpectedValue(Box::new(Value::Bool(true)))),
Error::ShortReturn(ShortReturnType::ExpectedValue(Box::new(Value::Bool(true))))
);
assert_eq!(
Error::Interpreter(InterpreterError::InterpreterError("".to_string())),
Error::Interpreter(InterpreterError::InterpreterError("".to_string()))
);
assert!(
Error::ShortReturn(ShortReturnType::ExpectedValue(Value::Bool(true)))
Error::ShortReturn(ShortReturnType::ExpectedValue(Box::new(Value::Bool(true))))
!= Error::Interpreter(InterpreterError::InterpreterError("".to_string()))
);
}
Expand Down
21 changes: 13 additions & 8 deletions clarity-types/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#![allow(clippy::result_large_err)]

pub mod serialization;
pub mod signatures;
Expand Down Expand Up @@ -455,7 +454,11 @@ impl SequenceData {
Ok(None)
}
} else {
Err(CheckErrors::TypeValueError(TypeSignature::min_buffer()?, to_find).into())
Err(CheckErrors::TypeValueError(
Box::new(TypeSignature::min_buffer()?),
Box::new(to_find),
)
.into())
}
}
SequenceData::List(data) => {
Expand All @@ -480,10 +483,11 @@ impl SequenceData {
Ok(None)
}
} else {
Err(
CheckErrors::TypeValueError(TypeSignature::min_string_ascii()?, to_find)
.into(),
Err(CheckErrors::TypeValueError(
Box::new(TypeSignature::min_string_ascii()?),
Box::new(to_find),
)
.into())
}
}
SequenceData::String(CharType::UTF8(data)) => {
Expand All @@ -500,10 +504,11 @@ impl SequenceData {
Ok(None)
}
} else {
Err(
CheckErrors::TypeValueError(TypeSignature::min_string_utf8()?, to_find)
.into(),
Err(CheckErrors::TypeValueError(
Box::new(TypeSignature::min_string_utf8()?),
Box::new(to_find),
)
.into())
}
}
}
Expand Down
37 changes: 24 additions & 13 deletions clarity-types/src/types/signatures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,8 @@ impl TypeSignature {
CallableSubtype::Principal(_) => {
if is_trait.is_some() {
return Err(CheckErrors::TypeError(
TypeSignature::CallableType(partial.clone()),
TypeSignature::PrincipalType,
Box::new(TypeSignature::CallableType(partial.clone())),
Box::new(TypeSignature::PrincipalType),
));
} else {
is_principal = true;
Expand All @@ -763,8 +763,8 @@ impl TypeSignature {
CallableSubtype::Trait(t) => {
if is_principal {
return Err(CheckErrors::TypeError(
TypeSignature::PrincipalType,
TypeSignature::CallableType(partial.clone()),
Box::new(TypeSignature::PrincipalType),
Box::new(TypeSignature::CallableType(partial.clone())),
));
} else {
is_trait = Some(t.clone());
Expand Down Expand Up @@ -1022,9 +1022,10 @@ impl TypeSignature {
) => {
let mut type_map_out = BTreeMap::new();
for (name, entry_a) in types_a.iter() {
let entry_b = types_b
.get(name)
.ok_or(CheckErrors::TypeError(a.clone(), b.clone()))?;
let entry_b = types_b.get(name).ok_or(CheckErrors::TypeError(
Box::new(a.clone()),
Box::new(b.clone()),
))?;
let entry_out = Self::least_supertype_v2_0(entry_a, entry_b)?;
type_map_out.insert(name.clone(), entry_out);
}
Expand Down Expand Up @@ -1110,7 +1111,10 @@ impl TypeSignature {
if x == y {
Ok(x.clone())
} else {
Err(CheckErrors::TypeError(a.clone(), b.clone()))
Err(CheckErrors::TypeError(
Box::new(a.clone()),
Box::new(b.clone()),
))
}
}
}
Expand All @@ -1127,9 +1131,10 @@ impl TypeSignature {
) => {
let mut type_map_out = BTreeMap::new();
for (name, entry_a) in types_a.iter() {
let entry_b = types_b
.get(name)
.ok_or(CheckErrors::TypeError(a.clone(), b.clone()))?;
let entry_b = types_b.get(name).ok_or(CheckErrors::TypeError(
Box::new(a.clone()),
Box::new(b.clone()),
))?;
let entry_out = Self::least_supertype_v2_1(entry_a, entry_b)?;
type_map_out.insert(name.clone(), entry_out);
}
Expand Down Expand Up @@ -1237,7 +1242,10 @@ impl TypeSignature {
if all_principals {
Ok(PrincipalType)
} else {
Err(CheckErrors::TypeError(a.clone(), b.clone()))
Err(CheckErrors::TypeError(
Box::new(a.clone()),
Box::new(b.clone()),
))
}
}
(ListUnionType(l1), ListUnionType(l2)) => {
Expand All @@ -1247,7 +1255,10 @@ impl TypeSignature {
if x == y {
Ok(x.clone())
} else {
Err(CheckErrors::TypeError(a.clone(), b.clone()))
Err(CheckErrors::TypeError(
Box::new(a.clone()),
Box::new(b.clone()),
))
}
}
}
Expand Down
Loading
Loading