Skip to content

Commit 985bb03

Browse files
committed
Merge branch 'develop' into chore/remove-unused-check-errors-variants
2 parents bc8ca17 + 68ab2bf commit 985bb03

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2207
-1750
lines changed

clarity-types/src/errors/analysis.rs

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -162,34 +162,34 @@ pub enum CheckErrors {
162162
// match errors
163163
BadMatchOptionSyntax(Box<CheckErrors>),
164164
BadMatchResponseSyntax(Box<CheckErrors>),
165-
BadMatchInput(TypeSignature),
165+
BadMatchInput(Box<TypeSignature>),
166166

167167
// list typing errors
168168
ListTypesMustMatch,
169169
ConstructedListTooLarge,
170170

171171
// simple type expectation mismatch
172-
TypeError(TypeSignature, TypeSignature),
173-
TypeValueError(TypeSignature, Value),
172+
TypeError(Box<TypeSignature>, Box<TypeSignature>),
173+
TypeValueError(Box<TypeSignature>, Box<Value>),
174174

175175
InvalidTypeDescription,
176176
UnknownTypeName(String),
177177

178178
// union type mismatch
179-
UnionTypeError(Vec<TypeSignature>, TypeSignature),
180-
UnionTypeValueError(Vec<TypeSignature>, Value),
181-
182-
ExpectedOptionalType(TypeSignature),
183-
ExpectedResponseType(TypeSignature),
184-
ExpectedOptionalOrResponseType(TypeSignature),
185-
ExpectedOptionalValue(Value),
186-
ExpectedResponseValue(Value),
187-
ExpectedOptionalOrResponseValue(Value),
179+
UnionTypeError(Vec<TypeSignature>, Box<TypeSignature>),
180+
UnionTypeValueError(Vec<TypeSignature>, Box<Value>),
181+
182+
ExpectedOptionalType(Box<TypeSignature>),
183+
ExpectedResponseType(Box<TypeSignature>),
184+
ExpectedOptionalOrResponseType(Box<TypeSignature>),
185+
ExpectedOptionalValue(Box<Value>),
186+
ExpectedResponseValue(Box<Value>),
187+
ExpectedOptionalOrResponseValue(Box<Value>),
188188
CouldNotDetermineResponseOkType,
189189
CouldNotDetermineResponseErrType,
190190
CouldNotDetermineSerializationType,
191191
UncheckedIntermediaryResponses,
192-
ExpectedContractPrincipalValue(Value),
192+
ExpectedContractPrincipalValue(Box<Value>),
193193

194194
CouldNotDetermineMatchTypes,
195195
CouldNotDetermineType,
@@ -212,7 +212,7 @@ pub enum CheckErrors {
212212

213213
// tuples
214214
BadTupleFieldName,
215-
ExpectedTuple(TypeSignature),
215+
ExpectedTuple(Box<TypeSignature>),
216216
NoSuchTupleField(String, TupleTypeSignature),
217217
EmptyTuplesNotAllowed,
218218
BadTupleConstruction(String),
@@ -228,9 +228,9 @@ pub enum CheckErrors {
228228
DefineFunctionBadSignature,
229229
BadFunctionName,
230230
BadMapTypeDefinition,
231-
PublicFunctionMustReturnResponse(TypeSignature),
231+
PublicFunctionMustReturnResponse(Box<TypeSignature>),
232232
DefineVariableBadSignature,
233-
ReturnTypesMustMatch(TypeSignature, TypeSignature),
233+
ReturnTypesMustMatch(Box<TypeSignature>, Box<TypeSignature>),
234234

235235
CircularReference(Vec<String>),
236236

@@ -240,7 +240,7 @@ pub enum CheckErrors {
240240
PublicFunctionNotReadOnly(String, String),
241241
ContractAlreadyExists(String),
242242
ContractCallExpectName,
243-
ExpectedCallableType(TypeSignature),
243+
ExpectedCallableType(Box<TypeSignature>),
244244

245245
// get-block-info? errors
246246
NoSuchBlockInfoProperty(String),
@@ -258,7 +258,7 @@ pub enum CheckErrors {
258258
// expect a function, or applying a function to a list
259259
NonFunctionApplication,
260260
ExpectedListApplication,
261-
ExpectedSequence(TypeSignature),
261+
ExpectedSequence(Box<TypeSignature>),
262262
MaxLengthOverflow,
263263

264264
// let syntax
@@ -275,9 +275,9 @@ pub enum CheckErrors {
275275
RequiresAtLeastArguments(usize, usize),
276276
RequiresAtMostArguments(usize, usize),
277277
IncorrectArgumentCount(usize, usize),
278-
IfArmsMustMatch(TypeSignature, TypeSignature),
279-
MatchArmsMustMatch(TypeSignature, TypeSignature),
280-
DefaultTypesMustMatch(TypeSignature, TypeSignature),
278+
IfArmsMustMatch(Box<TypeSignature>, Box<TypeSignature>),
279+
MatchArmsMustMatch(Box<TypeSignature>, Box<TypeSignature>),
280+
DefaultTypesMustMatch(Box<TypeSignature>, Box<TypeSignature>),
281281
IllegalOrUnknownFunctionApplication(String),
282282
UnknownFunction(String),
283283

@@ -293,7 +293,7 @@ pub enum CheckErrors {
293293
UnexpectedTraitOrFieldReference,
294294
TraitBasedContractCallInReadOnly,
295295
ContractOfExpectsTrait,
296-
IncompatibleTrait(TraitIdentifier, TraitIdentifier),
296+
IncompatibleTrait(Box<TraitIdentifier>, Box<TraitIdentifier>),
297297

298298
// strings
299299
InvalidCharactersDetected,
@@ -311,7 +311,7 @@ pub enum CheckErrors {
311311

312312
#[derive(Debug, PartialEq)]
313313
pub struct CheckError {
314-
pub err: CheckErrors,
314+
pub err: Box<CheckErrors>,
315315
pub expressions: Option<Vec<SymbolicExpression>>,
316316
pub diagnostic: Diagnostic,
317317
}
@@ -331,7 +331,7 @@ impl CheckError {
331331
pub fn new(err: CheckErrors) -> CheckError {
332332
let diagnostic = Diagnostic::err(&err);
333333
CheckError {
334-
err,
334+
err: Box::new(err),
335335
expressions: None,
336336
diagnostic,
337337
}
@@ -446,7 +446,6 @@ impl From<CheckErrors> for String {
446446
}
447447
}
448448

449-
#[allow(clippy::result_large_err)]
450449
pub fn check_argument_count<T>(expected: usize, args: &[T]) -> Result<(), CheckErrors> {
451450
if args.len() != expected {
452451
Err(CheckErrors::IncorrectArgumentCount(expected, args.len()))
@@ -455,7 +454,6 @@ pub fn check_argument_count<T>(expected: usize, args: &[T]) -> Result<(), CheckE
455454
}
456455
}
457456

458-
#[allow(clippy::result_large_err)]
459457
pub fn check_arguments_at_least<T>(expected: usize, args: &[T]) -> Result<(), CheckErrors> {
460458
if args.len() < expected {
461459
Err(CheckErrors::RequiresAtLeastArguments(expected, args.len()))
@@ -464,7 +462,6 @@ pub fn check_arguments_at_least<T>(expected: usize, args: &[T]) -> Result<(), Ch
464462
}
465463
}
466464

467-
#[allow(clippy::result_large_err)]
468465
pub fn check_arguments_at_most<T>(expected: usize, args: &[T]) -> Result<(), CheckErrors> {
469466
if args.len() > expected {
470467
Err(CheckErrors::RequiresAtMostArguments(expected, args.len()))

clarity-types/src/errors/ast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub enum ParseErrors {
9898

9999
#[derive(Debug, PartialEq)]
100100
pub struct ParseError {
101-
pub err: ParseErrors,
101+
pub err: Box<ParseErrors>,
102102
pub pre_expressions: Option<Vec<PreSymbolicExpression>>,
103103
pub diagnostic: Diagnostic,
104104
}
@@ -107,14 +107,14 @@ impl ParseError {
107107
pub fn new(err: ParseErrors) -> ParseError {
108108
let diagnostic = Diagnostic::err(&err);
109109
ParseError {
110-
err,
110+
err: Box::new(err),
111111
pre_expressions: None,
112112
diagnostic,
113113
}
114114
}
115115

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

120120
pub fn has_pre_expression(&self) -> bool {

clarity-types/src/errors/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub enum RuntimeErrorType {
8282
// error in parsing types
8383
ParseError(String),
8484
// error in parsing the AST
85-
ASTError(ParseError),
85+
ASTError(Box<ParseError>),
8686
MaxStackDepthReached,
8787
MaxContextDepthReached,
8888
BadTypeConstruction,
@@ -103,8 +103,8 @@ pub enum RuntimeErrorType {
103103

104104
#[derive(Debug, PartialEq)]
105105
pub enum ShortReturnType {
106-
ExpectedValue(Value),
107-
AssertionFailed(Value),
106+
ExpectedValue(Box<Value>),
107+
AssertionFailed(Box<Value>),
108108
}
109109

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

166166
impl From<ParseError> for Error {
167167
fn from(err: ParseError) -> Self {
168-
match &err.err {
168+
match *err.err {
169169
ParseErrors::InterpreterFailure => Error::from(InterpreterError::Expect(
170170
"Unexpected interpreter failure during parsing".into(),
171171
)),
172-
_ => Error::from(RuntimeErrorType::ASTError(err)),
172+
_ => Error::from(RuntimeErrorType::ASTError(Box::new(err))),
173173
}
174174
}
175175
}
@@ -226,8 +226,8 @@ impl From<Error> for () {
226226
impl From<ShortReturnType> for Value {
227227
fn from(val: ShortReturnType) -> Self {
228228
match val {
229-
ShortReturnType::ExpectedValue(v) => v,
230-
ShortReturnType::AssertionFailed(v) => v,
229+
ShortReturnType::ExpectedValue(v) => *v,
230+
ShortReturnType::AssertionFailed(v) => *v,
231231
}
232232
}
233233
}
@@ -239,15 +239,15 @@ mod test {
239239
#[test]
240240
fn equality() {
241241
assert_eq!(
242-
Error::ShortReturn(ShortReturnType::ExpectedValue(Value::Bool(true))),
243-
Error::ShortReturn(ShortReturnType::ExpectedValue(Value::Bool(true)))
242+
Error::ShortReturn(ShortReturnType::ExpectedValue(Box::new(Value::Bool(true)))),
243+
Error::ShortReturn(ShortReturnType::ExpectedValue(Box::new(Value::Bool(true))))
244244
);
245245
assert_eq!(
246246
Error::Interpreter(InterpreterError::InterpreterError("".to_string())),
247247
Error::Interpreter(InterpreterError::InterpreterError("".to_string()))
248248
);
249249
assert!(
250-
Error::ShortReturn(ShortReturnType::ExpectedValue(Value::Bool(true)))
250+
Error::ShortReturn(ShortReturnType::ExpectedValue(Box::new(Value::Bool(true))))
251251
!= Error::Interpreter(InterpreterError::InterpreterError("".to_string()))
252252
);
253253
}

clarity-types/src/types/mod.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
//
1313
// You should have received a copy of the GNU General Public License
1414
// along with this program. If not, see <http://www.gnu.org/licenses/>.
15-
#![allow(clippy::result_large_err)]
1615

1716
pub mod serialization;
1817
pub mod signatures;
@@ -455,7 +454,11 @@ impl SequenceData {
455454
Ok(None)
456455
}
457456
} else {
458-
Err(CheckErrors::TypeValueError(TypeSignature::min_buffer()?, to_find).into())
457+
Err(CheckErrors::TypeValueError(
458+
Box::new(TypeSignature::min_buffer()?),
459+
Box::new(to_find),
460+
)
461+
.into())
459462
}
460463
}
461464
SequenceData::List(data) => {
@@ -480,10 +483,11 @@ impl SequenceData {
480483
Ok(None)
481484
}
482485
} else {
483-
Err(
484-
CheckErrors::TypeValueError(TypeSignature::min_string_ascii()?, to_find)
485-
.into(),
486+
Err(CheckErrors::TypeValueError(
487+
Box::new(TypeSignature::min_string_ascii()?),
488+
Box::new(to_find),
486489
)
490+
.into())
487491
}
488492
}
489493
SequenceData::String(CharType::UTF8(data)) => {
@@ -500,10 +504,11 @@ impl SequenceData {
500504
Ok(None)
501505
}
502506
} else {
503-
Err(
504-
CheckErrors::TypeValueError(TypeSignature::min_string_utf8()?, to_find)
505-
.into(),
507+
Err(CheckErrors::TypeValueError(
508+
Box::new(TypeSignature::min_string_utf8()?),
509+
Box::new(to_find),
506510
)
511+
.into())
507512
}
508513
}
509514
}

clarity-types/src/types/signatures.rs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -753,8 +753,8 @@ impl TypeSignature {
753753
CallableSubtype::Principal(_) => {
754754
if is_trait.is_some() {
755755
return Err(CheckErrors::TypeError(
756-
TypeSignature::CallableType(partial.clone()),
757-
TypeSignature::PrincipalType,
756+
Box::new(TypeSignature::CallableType(partial.clone())),
757+
Box::new(TypeSignature::PrincipalType),
758758
));
759759
} else {
760760
is_principal = true;
@@ -763,8 +763,8 @@ impl TypeSignature {
763763
CallableSubtype::Trait(t) => {
764764
if is_principal {
765765
return Err(CheckErrors::TypeError(
766-
TypeSignature::PrincipalType,
767-
TypeSignature::CallableType(partial.clone()),
766+
Box::new(TypeSignature::PrincipalType),
767+
Box::new(TypeSignature::CallableType(partial.clone())),
768768
));
769769
} else {
770770
is_trait = Some(t.clone());
@@ -1039,9 +1039,10 @@ impl TypeSignature {
10391039
) => {
10401040
let mut type_map_out = BTreeMap::new();
10411041
for (name, entry_a) in types_a.iter() {
1042-
let entry_b = types_b
1043-
.get(name)
1044-
.ok_or(CheckErrors::TypeError(a.clone(), b.clone()))?;
1042+
let entry_b = types_b.get(name).ok_or(CheckErrors::TypeError(
1043+
Box::new(a.clone()),
1044+
Box::new(b.clone()),
1045+
))?;
10451046
let entry_out = Self::least_supertype_v2_0(entry_a, entry_b)?;
10461047
type_map_out.insert(name.clone(), entry_out);
10471048
}
@@ -1127,7 +1128,10 @@ impl TypeSignature {
11271128
if x == y {
11281129
Ok(x.clone())
11291130
} else {
1130-
Err(CheckErrors::TypeError(a.clone(), b.clone()))
1131+
Err(CheckErrors::TypeError(
1132+
Box::new(a.clone()),
1133+
Box::new(b.clone()),
1134+
))
11311135
}
11321136
}
11331137
}
@@ -1144,9 +1148,10 @@ impl TypeSignature {
11441148
) => {
11451149
let mut type_map_out = BTreeMap::new();
11461150
for (name, entry_a) in types_a.iter() {
1147-
let entry_b = types_b
1148-
.get(name)
1149-
.ok_or(CheckErrors::TypeError(a.clone(), b.clone()))?;
1151+
let entry_b = types_b.get(name).ok_or(CheckErrors::TypeError(
1152+
Box::new(a.clone()),
1153+
Box::new(b.clone()),
1154+
))?;
11501155
let entry_out = Self::least_supertype_v2_1(entry_a, entry_b)?;
11511156
type_map_out.insert(name.clone(), entry_out);
11521157
}
@@ -1254,7 +1259,10 @@ impl TypeSignature {
12541259
if all_principals {
12551260
Ok(PrincipalType)
12561261
} else {
1257-
Err(CheckErrors::TypeError(a.clone(), b.clone()))
1262+
Err(CheckErrors::TypeError(
1263+
Box::new(a.clone()),
1264+
Box::new(b.clone()),
1265+
))
12581266
}
12591267
}
12601268
(ListUnionType(l1), ListUnionType(l2)) => {
@@ -1264,7 +1272,10 @@ impl TypeSignature {
12641272
if x == y {
12651273
Ok(x.clone())
12661274
} else {
1267-
Err(CheckErrors::TypeError(a.clone(), b.clone()))
1275+
Err(CheckErrors::TypeError(
1276+
Box::new(a.clone()),
1277+
Box::new(b.clone()),
1278+
))
12681279
}
12691280
}
12701281
}

0 commit comments

Comments
 (0)