From b573b0b619a2dc842a8d17220a6180089209fea7 Mon Sep 17 00:00:00 2001 From: Francesco Leacche Date: Thu, 7 Aug 2025 22:07:56 +0100 Subject: [PATCH 1/2] fix clippy result_large_err --- clarity-serialization/src/errors/analysis.rs | 51 +- clarity-serialization/src/errors/ast.rs | 6 +- clarity-serialization/src/errors/mod.rs | 22 +- clarity-serialization/src/types/mod.rs | 21 +- clarity-serialization/src/types/signatures.rs | 37 +- clarity/src/vm/analysis/mod.rs | 11 +- .../vm/analysis/read_only_checker/tests.rs | 18 +- .../src/vm/analysis/trait_checker/tests.rs | 81 +- .../src/vm/analysis/type_checker/v2_05/mod.rs | 59 +- .../type_checker/v2_05/natives/maps.rs | 16 +- .../type_checker/v2_05/natives/mod.rs | 19 +- .../type_checker/v2_05/natives/options.rs | 29 +- .../type_checker/v2_05/natives/sequences.rs | 36 +- .../type_checker/v2_05/tests/assets.rs | 112 ++- .../type_checker/v2_05/tests/contracts.rs | 28 +- .../analysis/type_checker/v2_05/tests/mod.rs | 307 +++---- .../src/vm/analysis/type_checker/v2_1/mod.rs | 131 +-- .../type_checker/v2_1/natives/maps.rs | 16 +- .../analysis/type_checker/v2_1/natives/mod.rs | 22 +- .../type_checker/v2_1/natives/options.rs | 32 +- .../type_checker/v2_1/natives/sequences.rs | 50 +- .../type_checker/v2_1/tests/assets.rs | 112 ++- .../type_checker/v2_1/tests/contracts.rs | 771 +++++++----------- .../analysis/type_checker/v2_1/tests/mod.rs | 660 ++++++++------- clarity/src/vm/ast/definition_sorter/tests.rs | 42 +- clarity/src/vm/ast/mod.rs | 14 +- clarity/src/vm/ast/parser/v1.rs | 56 +- clarity/src/vm/ast/parser/v2/mod.rs | 6 +- clarity/src/vm/callables.rs | 20 +- clarity/src/vm/clarity.rs | 16 +- clarity/src/vm/contexts.rs | 14 +- clarity/src/vm/database/clarity_db.rs | 54 +- clarity/src/vm/functions/arithmetic.rs | 30 +- clarity/src/vm/functions/assets.rs | 84 +- clarity/src/vm/functions/boolean.rs | 6 +- clarity/src/vm/functions/conversions.rs | 26 +- clarity/src/vm/functions/crypto.rs | 74 +- clarity/src/vm/functions/database.rs | 33 +- clarity/src/vm/functions/define.rs | 6 +- clarity/src/vm/functions/mod.rs | 14 +- clarity/src/vm/functions/options.rs | 22 +- clarity/src/vm/functions/principals.rs | 38 +- clarity/src/vm/functions/sequences.rs | 59 +- clarity/src/vm/functions/tuples.rs | 15 +- clarity/src/vm/mod.rs | 2 - clarity/src/vm/tests/contracts.rs | 17 +- clarity/src/vm/tests/datamaps.rs | 2 +- clarity/src/vm/tests/defines.rs | 95 +-- clarity/src/vm/tests/principals.rs | 33 +- clarity/src/vm/tests/sequences.rs | 109 +-- clarity/src/vm/tests/simple_apply_eval.rs | 130 +-- clarity/src/vm/tests/variables.rs | 8 +- clarity/src/vm/tooling/mod.rs | 2 +- pox-locking/src/lib.rs | 2 - stacks-signer/src/lib.rs | 1 - .../chainstate/stacks/boot/contract_tests.rs | 2 +- .../src/chainstate/stacks/db/transactions.rs | 6 +- stackslib/src/chainstate/stacks/miner.rs | 6 +- stackslib/src/clarity_cli.rs | 36 +- stackslib/src/clarity_vm/clarity.rs | 2 +- stackslib/src/clarity_vm/tests/contracts.rs | 28 +- stackslib/src/net/relay.rs | 2 +- 62 files changed, 2091 insertions(+), 1668 deletions(-) diff --git a/clarity-serialization/src/errors/analysis.rs b/clarity-serialization/src/errors/analysis.rs index 8831198579a..a015e350c19 100644 --- a/clarity-serialization/src/errors/analysis.rs +++ b/clarity-serialization/src/errors/analysis.rs @@ -43,7 +43,7 @@ pub enum CheckErrors { // match errors BadMatchOptionSyntax(Box), BadMatchResponseSyntax(Box), - BadMatchInput(TypeSignature), + BadMatchInput(Box), // list typing errors UnknownListConstructionFailure, @@ -51,25 +51,25 @@ pub enum CheckErrors { ConstructedListTooLarge, // simple type expectation mismatch - TypeError(TypeSignature, TypeSignature), - TypeLiteralError(TypeSignature, TypeSignature), - TypeValueError(TypeSignature, Value), + TypeError(Box, Box), + TypeLiteralError(Box, Box), + TypeValueError(Box, Box), - NoSuperType(TypeSignature, TypeSignature), + NoSuperType(Box, Box), InvalidTypeDescription, UnknownTypeName(String), // union type mismatch - UnionTypeError(Vec, TypeSignature), - UnionTypeValueError(Vec, Value), + UnionTypeError(Vec, Box), + UnionTypeValueError(Vec, Box), ExpectedLiteral, - ExpectedOptionalType(TypeSignature), - ExpectedResponseType(TypeSignature), - ExpectedOptionalOrResponseType(TypeSignature), - ExpectedOptionalValue(Value), - ExpectedResponseValue(Value), - ExpectedOptionalOrResponseValue(Value), + ExpectedOptionalType(Box), + ExpectedResponseType(Box), + ExpectedOptionalOrResponseType(Box), + ExpectedOptionalValue(Box), + ExpectedResponseValue(Box), + ExpectedOptionalOrResponseValue(Box), CouldNotDetermineResponseOkType, CouldNotDetermineResponseErrType, CouldNotDetermineSerializationType, @@ -98,7 +98,7 @@ pub enum CheckErrors { // tuples BadTupleFieldName, - ExpectedTuple(TypeSignature), + ExpectedTuple(Box), NoSuchTupleField(String, TupleTypeSignature), EmptyTuplesNotAllowed, BadTupleConstruction, @@ -115,9 +115,9 @@ pub enum CheckErrors { DefineFunctionBadSignature, BadFunctionName, BadMapTypeDefinition, - PublicFunctionMustReturnResponse(TypeSignature), + PublicFunctionMustReturnResponse(Box), DefineVariableBadSignature, - ReturnTypesMustMatch(TypeSignature, TypeSignature), + ReturnTypesMustMatch(Box, Box), CircularReference(Vec), @@ -127,7 +127,7 @@ pub enum CheckErrors { PublicFunctionNotReadOnly(String, String), ContractAlreadyExists(String), ContractCallExpectName, - ExpectedCallableType(TypeSignature), + ExpectedCallableType(Box), // get-block-info? errors NoSuchBlockInfoProperty(String), @@ -145,7 +145,7 @@ pub enum CheckErrors { // expect a function, or applying a function to a list NonFunctionApplication, ExpectedListApplication, - ExpectedSequence(TypeSignature), + ExpectedSequence(Box), MaxLengthOverflow, // let syntax @@ -163,9 +163,9 @@ pub enum CheckErrors { RequiresAtLeastArguments(usize, usize), RequiresAtMostArguments(usize, usize), IncorrectArgumentCount(usize, usize), - IfArmsMustMatch(TypeSignature, TypeSignature), - MatchArmsMustMatch(TypeSignature, TypeSignature), - DefaultTypesMustMatch(TypeSignature, TypeSignature), + IfArmsMustMatch(Box, Box), + MatchArmsMustMatch(Box, Box), + DefaultTypesMustMatch(Box, Box), TooManyExpressions, IllegalOrUnknownFunctionApplication(String), UnknownFunction(String), @@ -183,7 +183,7 @@ pub enum CheckErrors { UnexpectedTraitOrFieldReference, TraitBasedContractCallInReadOnly, ContractOfExpectsTrait, - IncompatibleTrait(TraitIdentifier, TraitIdentifier), + IncompatibleTrait(Box, Box), // strings InvalidCharactersDetected, @@ -201,7 +201,7 @@ pub enum CheckErrors { #[derive(Debug, PartialEq)] pub struct CheckError { - pub err: CheckErrors, + pub err: Box, pub expressions: Option>, pub diagnostic: Diagnostic, } @@ -221,7 +221,7 @@ impl CheckError { pub fn new(err: CheckErrors) -> CheckError { let diagnostic = Diagnostic::err(&err); CheckError { - err, + err: Box::new(err), expressions: None, diagnostic, } @@ -310,7 +310,6 @@ impl From for String { } } -#[allow(clippy::result_large_err)] pub fn check_argument_count(expected: usize, args: &[T]) -> Result<(), CheckErrors> { if args.len() != expected { Err(CheckErrors::IncorrectArgumentCount(expected, args.len())) @@ -319,7 +318,6 @@ pub fn check_argument_count(expected: usize, args: &[T]) -> Result<(), CheckE } } -#[allow(clippy::result_large_err)] pub fn check_arguments_at_least(expected: usize, args: &[T]) -> Result<(), CheckErrors> { if args.len() < expected { Err(CheckErrors::RequiresAtLeastArguments(expected, args.len())) @@ -328,7 +326,6 @@ pub fn check_arguments_at_least(expected: usize, args: &[T]) -> Result<(), Ch } } -#[allow(clippy::result_large_err)] pub fn check_arguments_at_most(expected: usize, args: &[T]) -> Result<(), CheckErrors> { if args.len() > expected { Err(CheckErrors::RequiresAtMostArguments(expected, args.len())) diff --git a/clarity-serialization/src/errors/ast.rs b/clarity-serialization/src/errors/ast.rs index 35ee8fca2d8..a61a7793938 100644 --- a/clarity-serialization/src/errors/ast.rs +++ b/clarity-serialization/src/errors/ast.rs @@ -97,7 +97,7 @@ pub enum ParseErrors { #[derive(Debug, PartialEq)] pub struct ParseError { - pub err: ParseErrors, + pub err: Box, pub pre_expressions: Option>, pub diagnostic: Diagnostic, } @@ -106,14 +106,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 { diff --git a/clarity-serialization/src/errors/mod.rs b/clarity-serialization/src/errors/mod.rs index e65fe47e621..5b05c9867ef 100644 --- a/clarity-serialization/src/errors/mod.rs +++ b/clarity-serialization/src/errors/mod.rs @@ -53,7 +53,7 @@ pub enum Error { /// Test executions may trigger these errors. #[derive(Debug, PartialEq)] pub enum InterpreterError { - BadSender(Value), + BadSender(Box), BadSymbolicRepresentation(String), InterpreterError(String), UninitializedPersistedVariable, @@ -85,7 +85,7 @@ pub enum RuntimeErrorType { // error in parsing types ParseError(String), // error in parsing the AST - ASTError(ParseError), + ASTError(Box), MaxStackDepthReached, MaxContextDepthReached, ListDimensionTooHigh, @@ -111,8 +111,8 @@ pub enum RuntimeErrorType { #[derive(Debug, PartialEq)] pub enum ShortReturnType { - ExpectedValue(Value), - AssertionFailed(Value), + ExpectedValue(Box), + AssertionFailed(Box), } pub type InterpreterResult = Result; @@ -173,11 +173,11 @@ impl error::Error for RuntimeErrorType { impl From 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))), } } } @@ -228,8 +228,8 @@ impl From for () { impl From 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, } } } @@ -241,15 +241,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())) ); } diff --git a/clarity-serialization/src/types/mod.rs b/clarity-serialization/src/types/mod.rs index 6b347583da8..52138e9e989 100644 --- a/clarity-serialization/src/types/mod.rs +++ b/clarity-serialization/src/types/mod.rs @@ -12,7 +12,6 @@ // // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#![allow(clippy::result_large_err)] pub mod serialization; pub mod signatures; @@ -442,7 +441,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) => { @@ -467,10 +470,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)) => { @@ -487,10 +491,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()) } } } diff --git a/clarity-serialization/src/types/signatures.rs b/clarity-serialization/src/types/signatures.rs index f03c5baac20..a2f9be350e9 100644 --- a/clarity-serialization/src/types/signatures.rs +++ b/clarity-serialization/src/types/signatures.rs @@ -708,8 +708,8 @@ impl TypeSignature { CallableSubtype::Principal(_) => { if is_trait.is_some() { return Err(CheckErrors::TypeError( - TypeSignature::PrincipalType, - TypeSignature::CallableType(partial.clone()), + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::CallableType(partial.clone())), )); } else { is_principal = true; @@ -718,8 +718,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()); @@ -965,9 +965,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); } @@ -1053,7 +1054,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()), + )) } } } @@ -1067,9 +1071,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); } @@ -1177,7 +1182,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)) => { @@ -1187,7 +1195,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()), + )) } } } diff --git a/clarity/src/vm/analysis/mod.rs b/clarity/src/vm/analysis/mod.rs index ddbcadb0c3d..516990560d5 100644 --- a/clarity/src/vm/analysis/mod.rs +++ b/clarity/src/vm/analysis/mod.rs @@ -92,7 +92,7 @@ pub fn mem_type_check( .cloned(); Ok((first_type, x)) } - Err((e, _)) => Err(e), + Err(e) => Err(e.0), } } @@ -119,7 +119,7 @@ pub fn type_check( *version, true, ) - .map_err(|(e, _cost_tracker)| e) + .map_err(|e| e.0) } #[allow(clippy::too_many_arguments)] @@ -132,7 +132,7 @@ pub fn run_analysis( epoch: StacksEpochId, version: ClarityVersion, build_type_map: bool, -) -> Result { +) -> Result> { let mut contract_analysis = ContractAnalysis::new( contract_identifier.clone(), expressions.to_vec(), @@ -177,7 +177,10 @@ pub fn run_analysis( }); match result { Ok(_) => Ok(contract_analysis), - Err(e) => Err((e, contract_analysis.take_contract_cost_tracker())), + Err(e) => Err(Box::new(( + e, + contract_analysis.take_contract_cost_tracker(), + ))), } } diff --git a/clarity/src/vm/analysis/read_only_checker/tests.rs b/clarity/src/vm/analysis/read_only_checker/tests.rs index 56eb0c47c62..585bea62cdc 100644 --- a/clarity/src/vm/analysis/read_only_checker/tests.rs +++ b/clarity/src/vm/analysis/read_only_checker/tests.rs @@ -44,7 +44,7 @@ fn test_argument_count_violations() { for (contract, expected) in examples.iter() { let err = mem_type_check(contract).unwrap_err(); - assert_eq!(&err.err, expected) + assert_eq!(*err.err, *expected) } } @@ -72,7 +72,7 @@ fn test_at_block_violations() { for contract in examples.iter() { let err = mem_type_check(contract).unwrap_err(); eprintln!("{err}"); - assert_eq!(err.err, CheckErrors::AtBlockClosureMustBeReadOnly) + assert_eq!(*err.err, CheckErrors::AtBlockClosureMustBeReadOnly) } } @@ -163,26 +163,24 @@ fn test_simple_read_only_violations() { for contract in bad_contracts.iter() { let err = mem_type_check(contract).unwrap_err(); - assert_eq!(err.err, CheckErrors::WriteAttemptedInReadOnly) + assert_eq!(*err.err, CheckErrors::WriteAttemptedInReadOnly) } } #[test] fn test_nested_writing_closure() { - let bad_contracts = [ - "(define-data-var cursor int 0) + let bad_contracts = ["(define-data-var cursor int 0) (define-public (bad-at-block-function) (begin (var-set cursor (at-block 0x0101010101010101010101010101010101010101010101010101010101010101 - ;; should be a read only error, caught in analysis, but it isn't + ;; should be a read only error, caught in analysis, but it isn't (begin (var-set cursor 1) 2))) - (ok 1)))" - ]; + (ok 1)))"]; for contract in bad_contracts.iter() { let err = mem_type_check(contract).unwrap_err(); - assert_eq!(err.err, CheckErrors::AtBlockClosureMustBeReadOnly) + assert_eq!(*err.err, CheckErrors::AtBlockClosureMustBeReadOnly) } } @@ -233,7 +231,7 @@ fn test_contract_call_read_only_violations( ) }) .unwrap_err(); - assert_eq!(err.err, CheckErrors::WriteAttemptedInReadOnly); + assert_eq!(*err.err, CheckErrors::WriteAttemptedInReadOnly); db.execute(|db| { type_check( diff --git a/clarity/src/vm/analysis/trait_checker/tests.rs b/clarity/src/vm/analysis/trait_checker/tests.rs index 2361cd1726a..305781f9593 100644 --- a/clarity/src/vm/analysis/trait_checker/tests.rs +++ b/clarity/src/vm/analysis/trait_checker/tests.rs @@ -97,7 +97,7 @@ fn test_incomplete_impl_trait_1(#[case] version: ClarityVersion, #[case] epoch: type_check(&impl_contract_id, &mut c3, db, true, &epoch, &version) }) .unwrap_err(); - match err.err { + match *err.err { CheckErrors::BadTraitImplementation(_, _) => {} _ => panic!("{err:?}"), } @@ -124,7 +124,7 @@ fn test_incomplete_impl_trait_2(#[case] version: ClarityVersion, #[case] epoch: type_check(&impl_contract_id, &mut c3, db, true, &epoch, &version) }) .unwrap_err(); - match err.err { + match *err.err { CheckErrors::BadTraitImplementation(_, _) => {} _ => panic!("{err:?}"), } @@ -148,7 +148,7 @@ fn test_impl_trait_arg_admission_1(#[case] version: ClarityVersion, #[case] epoc type_check(&impl_contract_id, &mut c3, db, true, &epoch, &version) }) .unwrap_err(); - match err.err { + match *err.err { CheckErrors::BadTraitImplementation(_, _) => {} _ => panic!("{err:?}"), } @@ -288,7 +288,7 @@ fn test_get_trait_reference_from_tuple( ) }) .unwrap_err(); - match err.err { + match *err.err { CheckErrors::ContractCallExpectName => {} _ => panic!("{err:?}"), } @@ -331,7 +331,7 @@ fn test_dynamic_dispatch_by_defining_and_impl_trait( ) }) .unwrap_err(); - match err.err { + match *err.err { CheckErrors::TraitReferenceUnknown(_) => {} _ => panic!("{err:?}"), } @@ -358,7 +358,7 @@ fn test_define_map_storing_trait_references( ) .unwrap_err(); - match err.err { + match *err.err { ParseErrors::TraitReferenceNotAllowed => {} _ => panic!("{err:?}"), } @@ -382,7 +382,7 @@ fn test_cycle_in_traits_1_contract(#[case] version: ClarityVersion, #[case] epoc epoch, ) .unwrap_err(); - match err.err { + match *err.err { ParseErrors::CircularReference(_) => {} _ => panic!("{err:?}"), } @@ -433,7 +433,7 @@ fn test_cycle_in_traits_2_contracts(#[case] version: ClarityVersion, #[case] epo ) }) .unwrap_err(); - match err.err { + match *err.err { CheckErrors::NoSuchContract(_) => {} _ => panic!("{err:?}"), } @@ -486,7 +486,7 @@ fn test_dynamic_dispatch_unknown_method( ) }) .unwrap_err(); - match err.err { + match *err.err { CheckErrors::TraitMethodUnknown(_, _) => {} _ => panic!("{err:?}"), } @@ -670,7 +670,7 @@ fn test_dynamic_dispatch_collision_trait( epoch, ) .unwrap_err(); - match err.err { + match *err.err { ParseErrors::NameAlreadyUsed(_) => {} _ => panic!("{err:?}"), } @@ -699,7 +699,7 @@ fn test_dynamic_dispatch_collision_defined_trait( epoch, ) .unwrap_err(); - match err.err { + match *err.err { ParseErrors::NameAlreadyUsed(_) => {} _ => panic!("{err:?}"), } @@ -739,7 +739,7 @@ fn test_dynamic_dispatch_collision_imported_trait( epoch, ) .unwrap_err(); - match err.err { + match *err.err { ParseErrors::NameAlreadyUsed(_) => {} _ => panic!("{err:?}"), } @@ -811,7 +811,7 @@ fn test_dynamic_dispatch_importing_non_existant_trait( ) }) .unwrap_err(); - match err.err { + match *err.err { CheckErrors::TraitReferenceUnknown(_) => {} _ => panic!("{err:?}"), } @@ -1098,13 +1098,21 @@ fn test_dynamic_dispatch_including_wrong_nested_trait( }) .unwrap_err(); - match err.err { - CheckErrors::TypeError( - TypeSignature::TraitReferenceType(_), - TypeSignature::TraitReferenceType(_), - ) if epoch < StacksEpochId::Epoch21 => {} - CheckErrors::TypeError(TypeSignature::CallableType(_), TypeSignature::CallableType(_)) - if epoch >= StacksEpochId::Epoch21 && version < ClarityVersion::Clarity2 => {} + match *err.err { + CheckErrors::TypeError(expected, actual) if epoch < StacksEpochId::Epoch21 => { + match (&*expected, &*actual) { + (TypeSignature::TraitReferenceType(_), TypeSignature::TraitReferenceType(_)) => {} + _ => panic!("unexpected TypeSignature: {expected:?} {actual:?}"), + } + } + CheckErrors::TypeError(expected, actual) + if epoch >= StacksEpochId::Epoch21 && version < ClarityVersion::Clarity2 => + { + match (&*expected, &*actual) { + (TypeSignature::CallableType(_), TypeSignature::CallableType(_)) => {} + _ => panic!("unexpected TypeSignature: {expected:?} {actual:?}"), + } + } CheckErrors::TraitReferenceUnknown(name) => assert_eq!(name.as_str(), "trait-a"), _ => panic!("{err:?}"), } @@ -1158,7 +1166,7 @@ fn test_dynamic_dispatch_mismatched_args( ) }) .unwrap_err(); - match err.err { + match *err.err { CheckErrors::TypeError(_, _) => {} _ => panic!("{err:?}"), } @@ -1212,7 +1220,7 @@ fn test_dynamic_dispatch_mismatched_returns( ) }) .unwrap_err(); - match err.err { + match *err.err { CheckErrors::BadTraitImplementation(_, _) => {} _ => panic!("{err:?}"), } @@ -1248,7 +1256,7 @@ fn test_bad_call_with_trait(#[case] version: ClarityVersion, #[case] epoch: Stac type_check(&call_contract_id, &mut c4, db, true, &epoch, &version) }) .unwrap_err(); - match err.err { + match *err.err { CheckErrors::TypeError(_, _) => {} _ => panic!("{err:?}"), } @@ -1457,7 +1465,7 @@ fn test_dynamic_dispatch_pass_bound_principal_as_trait_in_user_defined_functions }); match result { Err(err) if version == ClarityVersion::Clarity1 => { - match err.err { + match *err.err { CheckErrors::TypeError(_, _) => {} _ => panic!("{err:?}"), }; @@ -1551,7 +1559,7 @@ fn test_contract_of_wrong_type(#[case] version: ClarityVersion, #[case] epoch: S ) }) .unwrap_err(); - match err_principal.err { + match *err_principal.err { CheckErrors::TraitReferenceUnknown(_) => {} _ => panic!("{err_principal:?}"), } @@ -1561,7 +1569,7 @@ fn test_contract_of_wrong_type(#[case] version: ClarityVersion, #[case] epoch: S type_check(&disp_contract_id, &mut c_int, db, true, &epoch, &version) }) .unwrap_err(); - match err_int.err { + match *err_int.err { CheckErrors::TraitReferenceUnknown(_) => {} _ => panic!("{err_int:?}"), } @@ -1571,7 +1579,7 @@ fn test_contract_of_wrong_type(#[case] version: ClarityVersion, #[case] epoch: S type_check(&disp_contract_id, &mut c_int, db, true, &epoch, &version) }) .unwrap_err(); - match err_uint.err { + match *err_uint.err { CheckErrors::TraitReferenceUnknown(_) => {} _ => panic!("{err_uint:?}"), } @@ -1581,7 +1589,7 @@ fn test_contract_of_wrong_type(#[case] version: ClarityVersion, #[case] epoch: S type_check(&disp_contract_id, &mut c_int, db, true, &epoch, &version) }) .unwrap_err(); - match err_bool.err { + match *err_bool.err { CheckErrors::TraitReferenceUnknown(_) => {} _ => panic!("{err_bool:?}"), } @@ -1591,7 +1599,7 @@ fn test_contract_of_wrong_type(#[case] version: ClarityVersion, #[case] epoch: S type_check(&disp_contract_id, &mut c_int, db, true, &epoch, &version) }) .unwrap_err(); - match err_list.err { + match *err_list.err { CheckErrors::TraitReferenceUnknown(_) => {} _ => panic!("{err_list:?}"), } @@ -1601,7 +1609,7 @@ fn test_contract_of_wrong_type(#[case] version: ClarityVersion, #[case] epoch: S type_check(&disp_contract_id, &mut c_int, db, true, &epoch, &version) }) .unwrap_err(); - match err_buff.err { + match *err_buff.err { CheckErrors::TraitReferenceUnknown(_) => {} _ => panic!("{err_buff:?}"), } @@ -1611,7 +1619,7 @@ fn test_contract_of_wrong_type(#[case] version: ClarityVersion, #[case] epoch: S type_check(&disp_contract_id, &mut c_int, db, true, &epoch, &version) }) .unwrap_err(); - match err_tuple.err { + match *err_tuple.err { CheckErrors::TraitReferenceUnknown(_) => {} _ => panic!("{err_tuple:?}"), } @@ -1810,11 +1818,12 @@ fn test_trait_contract_not_found(#[case] version: ClarityVersion, #[case] epoch: &version, ) }) { - Err(CheckError { - err: CheckErrors::NoSuchContract(contract), - expressions: _, - diagnostic: _, - }) if version < ClarityVersion::Clarity2 => assert!(contract.ends_with(".trait-contract")), + Err(CheckError { err, .. }) if version < ClarityVersion::Clarity2 => match *err { + CheckErrors::NoSuchContract(contract) => { + assert!(contract.ends_with(".trait-contract")) + } + _ => panic!("{version}: unexpected NoSuchContract error"), + }, Ok(_) if version >= ClarityVersion::Clarity2 => (), res => panic!("{version}: {res:?}"), } diff --git a/clarity/src/vm/analysis/type_checker/v2_05/mod.rs b/clarity/src/vm/analysis/type_checker/v2_05/mod.rs index 4a704abb66f..aaa31e5c617 100644 --- a/clarity/src/vm/analysis/type_checker/v2_05/mod.rs +++ b/clarity/src/vm/analysis/type_checker/v2_05/mod.rs @@ -149,8 +149,8 @@ impl FunctionType { analysis_typecheck_cost(accounting, expected_type, found_type)?; if !expected_type.admits_type(&StacksEpochId::Epoch2_05, found_type)? { return Err(CheckErrors::TypeError( - expected_type.clone(), - found_type.clone(), + Box::new(expected_type.clone()), + Box::new(found_type.clone()), ) .into()); } @@ -167,8 +167,8 @@ impl FunctionType { analysis_typecheck_cost(accounting, expected_type, found_type)?; if !expected_type.admits_type(&StacksEpochId::Epoch2_05, found_type)? { return Err(CheckErrors::TypeError( - expected_type.clone(), - found_type.clone(), + Box::new(expected_type.clone()), + Box::new(found_type.clone()), ) .into()); } @@ -184,7 +184,10 @@ impl FunctionType { return Ok(return_type.clone()); } } - Err(CheckErrors::UnionTypeError(arg_types.clone(), found_type.clone()).into()) + Err( + CheckErrors::UnionTypeError(arg_types.clone(), Box::new(found_type.clone())) + .into(), + ) } FunctionType::ArithmeticVariadic | FunctionType::ArithmeticBinary @@ -204,13 +207,17 @@ impl FunctionType { TypeSignature::UIntType => Ok(TypeSignature::UIntType), _ => Err(CheckErrors::UnionTypeError( vec![TypeSignature::IntType, TypeSignature::UIntType], - first.clone(), + Box::new(first.clone()), )), }?; for found_type in rest.iter() { analysis_typecheck_cost(accounting, &TypeSignature::IntType, found_type)?; if found_type != &return_type { - return Err(CheckErrors::TypeError(return_type, found_type.clone()).into()); + return Err(CheckErrors::TypeError( + Box::new(return_type), + Box::new(found_type.clone()), + ) + .into()); } } Ok(return_type) @@ -224,13 +231,17 @@ impl FunctionType { if first != &TypeSignature::IntType && first != &TypeSignature::UIntType { return Err(CheckErrors::UnionTypeError( vec![TypeSignature::IntType, TypeSignature::UIntType], - first.clone(), + Box::new(first.clone()), ) .into()); } if first != second { - return Err(CheckErrors::TypeError(first.clone(), second.clone()).into()); + return Err(CheckErrors::TypeError( + Box::new(first.clone()), + Box::new(second.clone()), + ) + .into()); } Ok(TypeSignature::BoolType) @@ -282,9 +293,11 @@ impl FunctionType { (expected_type, value) => { if !expected_type.admits(&StacksEpochId::Epoch2_05, value)? { let actual_type = TypeSignature::type_of(value)?; - return Err( - CheckErrors::TypeError(expected_type.clone(), actual_type).into() - ); + return Err(CheckErrors::TypeError( + Box::new(expected_type.clone()), + Box::new(actual_type), + ) + .into()); } } } @@ -374,7 +387,12 @@ impl<'a, 'b> TypeChecker<'a, 'b> { &expected_type, &return_type, ) - .map_err(|_| CheckErrors::ReturnTypesMustMatch(expected_type, return_type))?, + .map_err(|_| { + CheckErrors::ReturnTypesMustMatch( + Box::new(expected_type), + Box::new(return_type), + ) + })?, None => return_type, }; @@ -472,7 +490,8 @@ impl<'a, 'b> TypeChecker<'a, 'b> { if !expected_type.admits_type(&StacksEpochId::Epoch2_05, &actual_type)? { let mut err: CheckError = - CheckErrors::TypeError(expected_type.clone(), actual_type).into(); + CheckErrors::TypeError(Box::new(expected_type.clone()), Box::new(actual_type)) + .into(); err.set_expression(expr); Err(err) } else { @@ -601,7 +620,10 @@ impl<'a, 'b> TypeChecker<'a, 'b> { &return_type, ) .map_err(|_| { - CheckErrors::ReturnTypesMustMatch(expected.clone(), return_type) + CheckErrors::ReturnTypesMustMatch( + Box::new(expected.clone()), + Box::new(return_type), + ) })? } else { return_type @@ -854,9 +876,10 @@ impl<'a, 'b> TypeChecker<'a, 'b> { .add_public_function_type(f_name, FunctionType::Fixed(f_type))?; return Ok(Some(())); } else { - return Err( - CheckErrors::PublicFunctionMustReturnResponse(f_type.returns).into(), - ); + return Err(CheckErrors::PublicFunctionMustReturnResponse(Box::new( + f_type.returns, + )) + .into()); } } DefineFunctionsParsed::ReadOnlyFunction { signature, body } => { diff --git a/clarity/src/vm/analysis/type_checker/v2_05/natives/maps.rs b/clarity/src/vm/analysis/type_checker/v2_05/natives/maps.rs index b8d36b2f825..9615a3e30ab 100644 --- a/clarity/src/vm/analysis/type_checker/v2_05/natives/maps.rs +++ b/clarity/src/vm/analysis/type_checker/v2_05/natives/maps.rs @@ -56,8 +56,8 @@ pub fn check_special_fetch_entry( if !expected_key_type.admits_type(&StacksEpochId::Epoch2_05, &key_type)? { Err(CheckError::new(CheckErrors::TypeError( - expected_key_type.clone(), - key_type, + Box::new(expected_key_type.clone()), + Box::new(key_type), ))) } else { Ok(option_type) @@ -89,8 +89,8 @@ pub fn check_special_delete_entry( if !expected_key_type.admits_type(&StacksEpochId::Epoch2_05, &key_type)? { Err(CheckError::new(CheckErrors::TypeError( - expected_key_type.clone(), - key_type, + Box::new(expected_key_type.clone()), + Box::new(key_type), ))) } else { Ok(TypeSignature::BoolType) @@ -130,13 +130,13 @@ fn check_set_or_insert_entry( if !expected_key_type.admits_type(&StacksEpochId::Epoch2_05, &key_type)? { Err(CheckError::new(CheckErrors::TypeError( - expected_key_type.clone(), - key_type, + Box::new(expected_key_type.clone()), + Box::new(key_type), ))) } else if !expected_value_type.admits_type(&StacksEpochId::Epoch2_05, &value_type)? { Err(CheckError::new(CheckErrors::TypeError( - expected_value_type.clone(), - value_type, + Box::new(expected_value_type.clone()), + Box::new(value_type), ))) } else { Ok(TypeSignature::BoolType) diff --git a/clarity/src/vm/analysis/type_checker/v2_05/natives/mod.rs b/clarity/src/vm/analysis/type_checker/v2_05/natives/mod.rs index 9e01c505402..1aebb86864d 100644 --- a/clarity/src/vm/analysis/type_checker/v2_05/natives/mod.rs +++ b/clarity/src/vm/analysis/type_checker/v2_05/natives/mod.rs @@ -140,10 +140,10 @@ fn check_special_get( let option_type = TypeSignature::new_option(inner_type)?; Ok(option_type) } else { - Err(CheckErrors::ExpectedTuple(*value_type_sig).into()) + Err(CheckErrors::ExpectedTuple(value_type_sig).into()) } } else { - Err(CheckErrors::ExpectedTuple(argument_type).into()) + Err(CheckErrors::ExpectedTuple(Box::new(argument_type)).into()) } } @@ -157,13 +157,13 @@ fn check_special_merge( let res = checker.type_check(&args[0], context)?; let mut base = match res { TypeSignature::TupleType(tuple_sig) => Ok(tuple_sig), - _ => Err(CheckErrors::ExpectedTuple(res.clone())), + _ => Err(CheckErrors::ExpectedTuple(Box::new(res.clone()))), }?; let res = checker.type_check(&args[1], context)?; let mut update = match res { TypeSignature::TupleType(tuple_sig) => Ok(tuple_sig), - _ => Err(CheckErrors::ExpectedTuple(res.clone())), + _ => Err(CheckErrors::ExpectedTuple(Box::new(res.clone()))), }?; runtime_cost( ClarityCostFunction::AnalysisCheckTupleMerge, @@ -296,8 +296,8 @@ fn check_special_set_var( if !expected_value_type.admits_type(&StacksEpochId::Epoch2_05, &value_type)? { Err(CheckError::new(CheckErrors::TypeError( - expected_value_type.clone(), - value_type, + Box::new(expected_value_type.clone()), + Box::new(value_type), ))) } else { Ok(TypeSignature::BoolType) @@ -317,7 +317,7 @@ fn check_special_equals( for x_type in arg_types.into_iter() { analysis_typecheck_cost(checker, &x_type, &arg_type)?; arg_type = TypeSignature::least_supertype(&StacksEpochId::Epoch2_05, &x_type, &arg_type) - .map_err(|_| CheckErrors::TypeError(x_type, arg_type))?; + .map_err(|_| CheckErrors::TypeError(Box::new(x_type), Box::new(arg_type)))?; } Ok(TypeSignature::BoolType) @@ -339,8 +339,9 @@ fn check_special_if( analysis_typecheck_cost(checker, expr1, expr2)?; - TypeSignature::least_supertype(&StacksEpochId::Epoch2_05, expr1, expr2) - .map_err(|_| CheckErrors::IfArmsMustMatch(expr1.clone(), expr2.clone()).into()) + TypeSignature::least_supertype(&StacksEpochId::Epoch2_05, expr1, expr2).map_err(|_| { + CheckErrors::IfArmsMustMatch(Box::new(expr1.clone()), Box::new(expr2.clone())).into() + }) } fn check_contract_call( diff --git a/clarity/src/vm/analysis/type_checker/v2_05/natives/options.rs b/clarity/src/vm/analysis/type_checker/v2_05/natives/options.rs index 5644ece9169..9c7439ddbb9 100644 --- a/clarity/src/vm/analysis/type_checker/v2_05/natives/options.rs +++ b/clarity/src/vm/analysis/type_checker/v2_05/natives/options.rs @@ -82,7 +82,7 @@ pub fn check_special_is_response( if let TypeSignature::ResponseType(_types) = input { Ok(TypeSignature::BoolType) } else { - Err(CheckErrors::ExpectedResponseType(input.clone()).into()) + Err(CheckErrors::ExpectedResponseType(Box::new(input)).into()) } } @@ -100,7 +100,7 @@ pub fn check_special_is_optional( if let TypeSignature::OptionalType(_type) = input { Ok(TypeSignature::BoolType) } else { - Err(CheckErrors::ExpectedOptionalType(input.clone()).into()) + Err(CheckErrors::ExpectedOptionalType(Box::new(input)).into()) } } @@ -119,9 +119,12 @@ pub fn check_special_default_to( if let TypeSignature::OptionalType(input_type) = input { let contained_type = *input_type; TypeSignature::least_supertype(&StacksEpochId::Epoch2_05, &default, &contained_type) - .map_err(|_| CheckErrors::DefaultTypesMustMatch(default, contained_type).into()) + .map_err(|_| { + CheckErrors::DefaultTypesMustMatch(Box::new(default), Box::new(contained_type)) + .into() + }) } else { - Err(CheckErrors::ExpectedOptionalType(input).into()) + Err(CheckErrors::ExpectedOptionalType(Box::new(input)).into()) } } @@ -159,7 +162,7 @@ fn inner_unwrap(input: TypeSignature, checker: &mut TypeChecker) -> TypeResult { Ok(ok_type) } } - _ => Err(CheckErrors::ExpectedOptionalOrResponseType(input).into()), + _ => Err(CheckErrors::ExpectedOptionalOrResponseType(Box::new(input)).into()), } } @@ -174,7 +177,7 @@ fn inner_unwrap_err(input: TypeSignature, checker: &mut TypeChecker) -> TypeResu Ok(err_type) } } else { - Err(CheckErrors::ExpectedResponseType(input).into()) + Err(CheckErrors::ExpectedResponseType(Box::new(input)).into()) } } @@ -242,7 +245,7 @@ pub fn check_special_try_ret( Ok(ok_type) } } - _ => Err(CheckErrors::ExpectedOptionalOrResponseType(input).into()), + _ => Err(CheckErrors::ExpectedOptionalOrResponseType(Box::new(input)).into()), } } @@ -330,7 +333,10 @@ fn check_special_match_opt( &some_branch_type, &none_branch_type, ) - .map_err(|_| CheckErrors::MatchArmsMustMatch(some_branch_type, none_branch_type).into()) + .map_err(|_| { + CheckErrors::MatchArmsMustMatch(Box::new(some_branch_type), Box::new(none_branch_type)) + .into() + }) } fn check_special_match_resp( @@ -369,7 +375,10 @@ fn check_special_match_resp( analysis_typecheck_cost(checker, &ok_branch_type, &err_branch_type)?; TypeSignature::least_supertype(&StacksEpochId::Epoch2_05, &ok_branch_type, &err_branch_type) - .map_err(|_| CheckErrors::MatchArmsMustMatch(ok_branch_type, err_branch_type).into()) + .map_err(|_| { + CheckErrors::MatchArmsMustMatch(Box::new(ok_branch_type), Box::new(err_branch_type)) + .into() + }) } pub fn check_special_match( @@ -388,6 +397,6 @@ pub fn check_special_match( TypeSignature::ResponseType(resp_type) => { check_special_match_resp(*resp_type, checker, &args[1..], context) } - _ => Err(CheckErrors::BadMatchInput(input).into()), + _ => Err(CheckErrors::BadMatchInput(Box::new(input)).into()), } } diff --git a/clarity/src/vm/analysis/type_checker/v2_05/natives/sequences.rs b/clarity/src/vm/analysis/type_checker/v2_05/natives/sequences.rs index e1bdb8cbbd1..c3800b5e720 100644 --- a/clarity/src/vm/analysis/type_checker/v2_05/natives/sequences.rs +++ b/clarity/src/vm/analysis/type_checker/v2_05/natives/sequences.rs @@ -98,7 +98,7 @@ pub fn check_special_map( // However that could lead to confusions when combining certain types: // ex: (map concat (list "hello " "hi ") "world") would fail, because // strings are handled as sequences. - return Err(CheckErrors::ExpectedSequence(argument_type).into()); + return Err(CheckErrors::ExpectedSequence(Box::new(argument_type)).into()); } }; func_args.push(entry_type); @@ -130,7 +130,9 @@ pub fn check_special_filter( { let input_type = match argument_type { TypeSignature::SequenceType(ref sequence_type) => Ok(sequence_type.unit_type()?), - _ => Err(CheckErrors::ExpectedSequence(argument_type.clone())), + _ => Err(CheckErrors::ExpectedSequence(Box::new( + argument_type.clone(), + ))), }?; let filter_type = function_type.check_args( @@ -141,7 +143,11 @@ pub fn check_special_filter( )?; if TypeSignature::BoolType != filter_type { - return Err(CheckErrors::TypeError(TypeSignature::BoolType, filter_type).into()); + return Err(CheckErrors::TypeError( + Box::new(TypeSignature::BoolType), + Box::new(filter_type), + ) + .into()); } } @@ -167,7 +173,7 @@ pub fn check_special_fold( let input_type = match argument_type { TypeSignature::SequenceType(sequence_type) => Ok(sequence_type.unit_type()?), - _ => Err(CheckErrors::ExpectedSequence(argument_type)), + _ => Err(CheckErrors::ExpectedSequence(Box::new(argument_type))), }?; let initial_value_type = checker.type_check(&args[2], context)?; @@ -247,11 +253,15 @@ pub fn check_special_concat( TypeSignature::SequenceType(StringType(UTF8(size.try_into()?))) } (_, _) => { - return Err(CheckErrors::TypeError(lhs_type.clone(), rhs_type.clone()).into()) + return Err(CheckErrors::TypeError( + Box::new(lhs_type.clone()), + Box::new(rhs_type.clone()), + ) + .into()) } } } - _ => return Err(CheckErrors::ExpectedSequence(lhs_type.clone()).into()), + _ => return Err(CheckErrors::ExpectedSequence(Box::new(lhs_type.clone())).into()), }; Ok(res) } @@ -299,7 +309,11 @@ pub fn check_special_as_max_len( SymbolicExpressionType::LiteralValue(Value::UInt(expected_len)) => expected_len, _ => { let expected_len_type = checker.type_check(&args[1], context)?; - return Err(CheckErrors::TypeError(TypeSignature::UIntType, expected_len_type).into()); + return Err(CheckErrors::TypeError( + Box::new(TypeSignature::UIntType), + Box::new(expected_len_type), + ) + .into()); } }; runtime_cost( @@ -337,7 +351,7 @@ pub fn check_special_as_max_len( StringUTF8Length::try_from(expected_len)?, )))), )), - _ => Err(CheckErrors::ExpectedSequence(sequence).into()), + _ => Err(CheckErrors::ExpectedSequence(Box::new(sequence)).into()), } } @@ -353,7 +367,7 @@ pub fn check_special_len( match collection_type { TypeSignature::SequenceType(_) => Ok(()), - _ => Err(CheckErrors::ExpectedSequence(collection_type)), + _ => Err(CheckErrors::ExpectedSequence(Box::new(collection_type))), }?; Ok(TypeSignature::UIntType) @@ -391,7 +405,7 @@ pub fn check_special_element_at( .map_err(|_| CheckErrors::Expects("Bad constructor".into()))?, )))), )), - _ => Err(CheckErrors::ExpectedSequence(collection_type).into()), + _ => Err(CheckErrors::ExpectedSequence(Box::new(collection_type)).into()), } } @@ -407,7 +421,7 @@ pub fn check_special_index_of( let expected_input_type = match list_type { TypeSignature::SequenceType(ref sequence_type) => Ok(sequence_type.unit_type()?), - _ => Err(CheckErrors::ExpectedSequence(list_type)), + _ => Err(CheckErrors::ExpectedSequence(Box::new(list_type))), }?; checker.type_check_expects(&args[1], context, &expected_input_type)?; diff --git a/clarity/src/vm/analysis/type_checker/v2_05/tests/assets.rs b/clarity/src/vm/analysis/type_checker/v2_05/tests/assets.rs index 3d1e8ad9d1f..75dbc4928f5 100644 --- a/clarity/src/vm/analysis/type_checker/v2_05/tests/assets.rs +++ b/clarity/src/vm/analysis/type_checker/v2_05/tests/assets.rs @@ -196,42 +196,108 @@ fn test_bad_asset_usage() { CheckErrors::NoSuchFT("stackoos".to_string()), CheckErrors::BadTokenName, CheckErrors::BadTokenName, - CheckErrors::TypeError(TypeSignature::PrincipalType, TypeSignature::UIntType), - CheckErrors::TypeError(TypeSignature::PrincipalType, TypeSignature::IntType), + CheckErrors::TypeError( + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::UIntType), + ), + CheckErrors::TypeError( + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::IntType), + ), CheckErrors::BadTokenName, CheckErrors::NoSuchNFT("stackoos".to_string()), - CheckErrors::TypeError(string_ascii_type(10), TypeSignature::UIntType), - CheckErrors::TypeError(string_ascii_type(10), string_ascii_type(15)), + CheckErrors::TypeError( + Box::new(string_ascii_type(10)), + Box::new(TypeSignature::UIntType), + ), + CheckErrors::TypeError( + Box::new(string_ascii_type(10)), + Box::new(string_ascii_type(15)), + ), CheckErrors::BadTokenName, CheckErrors::NoSuchNFT("stackoos".to_string()), - CheckErrors::TypeError(string_ascii_type(10), TypeSignature::UIntType), - CheckErrors::TypeError(string_ascii_type(10), string_ascii_type(15)), - CheckErrors::TypeError(TypeSignature::PrincipalType, TypeSignature::UIntType), + CheckErrors::TypeError( + Box::new(string_ascii_type(10)), + Box::new(TypeSignature::UIntType), + ), + CheckErrors::TypeError( + Box::new(string_ascii_type(10)), + Box::new(string_ascii_type(15)), + ), + CheckErrors::TypeError( + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::UIntType), + ), CheckErrors::NoSuchFT("stackoos".to_string()), CheckErrors::BadTokenName, - CheckErrors::TypeError(TypeSignature::PrincipalType, TypeSignature::UIntType), - CheckErrors::TypeError(TypeSignature::UIntType, TypeSignature::BoolType), + CheckErrors::TypeError( + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::UIntType), + ), + CheckErrors::TypeError( + Box::new(TypeSignature::UIntType), + Box::new(TypeSignature::BoolType), + ), CheckErrors::BadTokenName, CheckErrors::NoSuchNFT("stackoos".to_string()), - CheckErrors::TypeError(TypeSignature::PrincipalType, TypeSignature::UIntType), - CheckErrors::TypeError(TypeSignature::PrincipalType, TypeSignature::UIntType), - CheckErrors::TypeError(string_ascii_type(10), TypeSignature::UIntType), + CheckErrors::TypeError( + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::UIntType), + ), + CheckErrors::TypeError( + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::UIntType), + ), + CheckErrors::TypeError( + Box::new(string_ascii_type(10)), + Box::new(TypeSignature::UIntType), + ), CheckErrors::BadTokenName, - CheckErrors::TypeError(string_ascii_type(10), TypeSignature::UIntType), - CheckErrors::TypeError(TypeSignature::PrincipalType, TypeSignature::UIntType), + CheckErrors::TypeError( + Box::new(string_ascii_type(10)), + Box::new(TypeSignature::UIntType), + ), + CheckErrors::TypeError( + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::UIntType), + ), CheckErrors::NoSuchFT("stackoos".to_string()), CheckErrors::BadTokenName, - CheckErrors::TypeError(TypeSignature::PrincipalType, TypeSignature::UIntType), - CheckErrors::TypeError(TypeSignature::UIntType, TypeSignature::BoolType), - CheckErrors::TypeError(TypeSignature::PrincipalType, TypeSignature::UIntType), - CheckErrors::TypeError(TypeSignature::UIntType, TypeSignature::BoolType), + CheckErrors::TypeError( + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::UIntType), + ), + CheckErrors::TypeError( + Box::new(TypeSignature::UIntType), + Box::new(TypeSignature::BoolType), + ), + CheckErrors::TypeError( + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::UIntType), + ), + CheckErrors::TypeError( + Box::new(TypeSignature::UIntType), + Box::new(TypeSignature::BoolType), + ), CheckErrors::DefineNFTBadSignature, - CheckErrors::TypeError(TypeSignature::UIntType, TypeSignature::IntType), - CheckErrors::TypeError(TypeSignature::UIntType, TypeSignature::IntType), + CheckErrors::TypeError( + Box::new(TypeSignature::UIntType), + Box::new(TypeSignature::IntType), + ), + CheckErrors::TypeError( + Box::new(TypeSignature::UIntType), + Box::new(TypeSignature::IntType), + ), CheckErrors::NoSuchFT("stackoos".to_string()), CheckErrors::NoSuchFT("stackoos".to_string()), - CheckErrors::TypeError(TypeSignature::UIntType, TypeSignature::IntType), - CheckErrors::TypeError(TypeSignature::PrincipalType, TypeSignature::IntType), + CheckErrors::TypeError( + Box::new(TypeSignature::UIntType), + Box::new(TypeSignature::IntType), + ), + CheckErrors::TypeError( + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::IntType), + ), ]; for (script, expected_err) in bad_scripts.iter().zip(expected.iter()) { @@ -243,6 +309,6 @@ fn test_bad_asset_usage() { ) .unwrap_err(); println!("{script}"); - assert_eq!(&actual_err.err, expected_err); + assert_eq!(*actual_err.err, *expected_err); } } diff --git a/clarity/src/vm/analysis/type_checker/v2_05/tests/contracts.rs b/clarity/src/vm/analysis/type_checker/v2_05/tests/contracts.rs index ed5a53d7bf4..6d37d068376 100644 --- a/clarity/src/vm/analysis/type_checker/v2_05/tests/contracts.rs +++ b/clarity/src/vm/analysis/type_checker/v2_05/tests/contracts.rs @@ -54,8 +54,8 @@ const SIMPLE_TOKENS: &str = "(define-map tokens { account: principal } { balance const SIMPLE_NAMES: &str = "(define-constant burn-address 'SP000000000000000000002Q6VF78) (define-private (price-function (name uint)) (if (< name u100000) u1000 u100)) - - (define-map name-map + + (define-map name-map { name: uint } { owner: principal }) (define-map preorder-map { name-hash: (buff 20) } @@ -64,7 +64,7 @@ const SIMPLE_NAMES: &str = "(define-constant burn-address 'SP0000000000000000000 (define-private (check-balance) (contract-call? .tokens my-get-token-balance tx-sender)) - (define-public (preorder + (define-public (preorder (name-hash (buff 20)) (name-price uint)) (let ((xfer-result (contract-call? .tokens token-transfer @@ -88,13 +88,13 @@ const SIMPLE_NAMES: &str = "(define-constant burn-address 'SP0000000000000000000 ;; preorder entry must exist! (unwrap! (map-get? preorder-map (tuple (name-hash (hash160 (xor name salt))))) (err 2))) - (name-entry + (name-entry (map-get? name-map (tuple (name name))))) (if (and ;; name shouldn't *already* exist (is-none name-entry) ;; preorder must have paid enough - (<= (price-function name) + (<= (price-function name) (get paid preorder-entry)) ;; preorder must have been the current principal (is-eq tx-sender @@ -231,7 +231,7 @@ fn test_names_tokens_contracts_interface() { { "name": "tn1", "type": "bool" }, { "name": "tn2", "type": "int128" }, { "name": "tn3", "type": { "buffer": { "length": 1 } }} - ] } } + ] } } }, { "name": "f11", "access": "private", @@ -364,7 +364,7 @@ fn test_names_tokens_contracts_interface() { "name": "n2", "type": "bool" } - ] + ] } }] } @@ -492,7 +492,7 @@ fn test_names_tokens_contracts_bad() { ) }) .unwrap_err(); - assert!(matches!(err.err, CheckErrors::TypeError(_, _))); + assert!(matches!(*err.err, CheckErrors::TypeError(_, _))); } #[test] @@ -534,11 +534,11 @@ fn test_bad_map_usage() { for contract in tests.iter() { let err = mem_type_check(contract, ClarityVersion::Clarity1, StacksEpochId::Epoch2_05) .unwrap_err(); - assert!(matches!(err.err, CheckErrors::TypeError(_, _))); + assert!(matches!(*err.err, CheckErrors::TypeError(_, _))); } assert!(matches!( - mem_type_check( + *mem_type_check( unhandled_option, ClarityVersion::Clarity1, StacksEpochId::Epoch2_05 @@ -663,7 +663,7 @@ fn test_expects() { ) .unwrap_err(); eprintln!("unmatched_return_types returned check error: {err}"); - assert!(matches!(err.err, CheckErrors::ReturnTypesMustMatch(_, _))); + assert!(matches!(*err.err, CheckErrors::ReturnTypesMustMatch(_, _))); } let err = mem_type_check( @@ -673,7 +673,7 @@ fn test_expects() { ) .unwrap_err(); eprintln!("bad_default_types returned check error: {err}"); - assert!(matches!(err.err, CheckErrors::DefaultTypesMustMatch(_, _))); + assert!(matches!(*err.err, CheckErrors::DefaultTypesMustMatch(_, _))); let err = mem_type_check( notype_response_type, @@ -683,7 +683,7 @@ fn test_expects() { .unwrap_err(); eprintln!("notype_response_type returned check error: {err}"); assert!(matches!( - err.err, + *err.err, CheckErrors::CouldNotDetermineResponseErrType )); @@ -695,7 +695,7 @@ fn test_expects() { .unwrap_err(); eprintln!("notype_response_type_2 returned check error: {err}"); assert!(matches!( - err.err, + *err.err, CheckErrors::CouldNotDetermineResponseOkType )); } diff --git a/clarity/src/vm/analysis/type_checker/v2_05/tests/mod.rs b/clarity/src/vm/analysis/type_checker/v2_05/tests/mod.rs index 47f3ed2389c..ea06e6d3801 100644 --- a/clarity/src/vm/analysis/type_checker/v2_05/tests/mod.rs +++ b/clarity/src/vm/analysis/type_checker/v2_05/tests/mod.rs @@ -73,8 +73,8 @@ fn test_get_block_info() { ]; let bad_expected = [ CheckErrors::NoSuchBlockInfoProperty("none".to_string()), - CheckErrors::TypeError(UIntType, BoolType), - CheckErrors::TypeError(UIntType, IntType), + CheckErrors::TypeError(Box::new(UIntType), Box::new(BoolType)), + CheckErrors::TypeError(Box::new(UIntType), Box::new(IntType)), CheckErrors::RequiresAtLeastArguments(2, 1), ]; @@ -86,7 +86,7 @@ fn test_get_block_info() { } for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -123,7 +123,7 @@ fn test_define_trait() { ]; for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } let bad = ["(define-trait trait-1)", "(define-trait)"]; @@ -142,7 +142,7 @@ fn test_define_trait() { StacksEpochId::Epoch2_05, ) .unwrap_err(); - assert_eq!(expected, &res.err); + assert_eq!(*expected, *res.err); } } @@ -171,7 +171,7 @@ fn test_use_trait() { StacksEpochId::Epoch2_05, ) .unwrap_err(); - assert_eq!(expected, &res.err); + assert_eq!(*expected, *res.err); } } @@ -193,7 +193,7 @@ fn test_impl_trait() { StacksEpochId::Epoch2_05, ) .unwrap_err(); - assert_eq!(expected, &res.err); + assert_eq!(*expected, *res.err); } } @@ -220,14 +220,14 @@ fn test_stx_ops() { ]; let bad_expected = [ CheckErrors::IncorrectArgumentCount(3, 2), - CheckErrors::TypeError(UIntType, IntType), - CheckErrors::TypeError(PrincipalType, UIntType), - CheckErrors::TypeError(PrincipalType, BoolType), + CheckErrors::TypeError(Box::new(UIntType), Box::new(IntType)), + CheckErrors::TypeError(Box::new(PrincipalType), Box::new(UIntType)), + CheckErrors::TypeError(Box::new(PrincipalType), Box::new(BoolType)), CheckErrors::IncorrectArgumentCount(2, 1), - CheckErrors::TypeError(UIntType, IntType), - CheckErrors::TypeError(PrincipalType, BoolType), + CheckErrors::TypeError(Box::new(UIntType), Box::new(IntType)), + CheckErrors::TypeError(Box::new(PrincipalType), Box::new(BoolType)), CheckErrors::IncorrectArgumentCount(2, 3), - CheckErrors::TypeError(PrincipalType, BoolType), + CheckErrors::TypeError(Box::new(PrincipalType), Box::new(BoolType)), CheckErrors::IncorrectArgumentCount(1, 2), ]; @@ -239,7 +239,7 @@ fn test_stx_ops() { } for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -294,11 +294,11 @@ fn test_destructuring_opts() { let bad = [ ( "(unwrap-err! (some 2) 2)", - CheckErrors::ExpectedResponseType(TypeSignature::from_string( + CheckErrors::ExpectedResponseType(Box::new(TypeSignature::from_string( "(optional int)", ClarityVersion::Clarity1, StacksEpochId::Epoch2_05, - )), + ))), ), ( "(unwrap! (err 3) 2)", @@ -335,11 +335,17 @@ fn test_destructuring_opts() { ( "(define-private (foo) (if (> 1 0) (ok 1) (err u8))) (match (foo) ok-val (+ 1 ok-val) err-val (/ err-val u0))", - CheckErrors::MatchArmsMustMatch(TypeSignature::IntType, TypeSignature::UIntType), + CheckErrors::MatchArmsMustMatch( + Box::new(TypeSignature::IntType), + Box::new(TypeSignature::UIntType), + ), ), ( "(match (some 1) inner-value (+ 1 inner-value) (> 1 28))", - CheckErrors::MatchArmsMustMatch(TypeSignature::IntType, TypeSignature::BoolType), + CheckErrors::MatchArmsMustMatch( + Box::new(TypeSignature::IntType), + Box::new(TypeSignature::BoolType), + ), ), ( "(match (some 1) inner-value (+ 1 inner-value))", @@ -366,15 +372,11 @@ fn test_destructuring_opts() { ("(match)", CheckErrors::RequiresAtLeastArguments(1, 0)), ( "(match 1 ok-val (/ ok-val 0) err-val (+ err-val 7))", - CheckErrors::BadMatchInput(TypeSignature::from_string( - "int", - ClarityVersion::Clarity1, - StacksEpochId::Epoch2_05, - )), + CheckErrors::BadMatchInput(Box::new(TypeSignature::IntType)), ), ( "(default-to 3 5)", - CheckErrors::ExpectedOptionalType(TypeSignature::IntType), + CheckErrors::ExpectedOptionalType(Box::new(TypeSignature::IntType)), ), ( "(define-private (foo (x int)) @@ -390,10 +392,14 @@ fn test_destructuring_opts() { (err u3) (ok (+ u2 (try! (t1 x))))))", CheckErrors::ReturnTypesMustMatch( - TypeSignature::new_response(TypeSignature::NoType, TypeSignature::BoolType) - .unwrap(), - TypeSignature::new_response(TypeSignature::UIntType, TypeSignature::UIntType) - .unwrap(), + Box::new( + TypeSignature::new_response(TypeSignature::NoType, TypeSignature::BoolType) + .unwrap(), + ), + Box::new( + TypeSignature::new_response(TypeSignature::UIntType, TypeSignature::UIntType) + .unwrap(), + ), ), ), ( @@ -401,9 +407,11 @@ fn test_destructuring_opts() { (define-private (t2 (x uint)) (> u2 (try! (t1 x))))", CheckErrors::ReturnTypesMustMatch( - TypeSignature::new_response(TypeSignature::NoType, TypeSignature::BoolType) - .unwrap(), - TypeSignature::BoolType, + Box::new( + TypeSignature::new_response(TypeSignature::NoType, TypeSignature::BoolType) + .unwrap(), + ), + Box::new(TypeSignature::BoolType), ), ), ( @@ -417,7 +425,7 @@ fn test_destructuring_opts() { ), ( "(try! 3)", - CheckErrors::ExpectedOptionalOrResponseType(TypeSignature::IntType), + CheckErrors::ExpectedOptionalOrResponseType(Box::new(TypeSignature::IntType)), ), ("(try! (ok 3) 4)", CheckErrors::IncorrectArgumentCount(1, 2)), ]; @@ -431,8 +439,8 @@ fn test_destructuring_opts() { for (bad_test, expected) in bad.iter() { assert_eq!( - expected, - &mem_type_check(bad_test, ClarityVersion::Clarity1, StacksEpochId::Epoch2_05) + *expected, + *mem_type_check(bad_test, ClarityVersion::Clarity1, StacksEpochId::Epoch2_05) .unwrap_err() .err ); @@ -446,7 +454,7 @@ fn test_at_block() { let bad = [ ( "(at-block (sha512 u0) u1)", - CheckErrors::TypeError(BUFF_32.clone(), BUFF_64.clone()), + CheckErrors::TypeError(Box::new(BUFF_32.clone()), Box::new(BUFF_64.clone())), ), ( "(at-block (sha256 u0) u1 u2)", @@ -462,7 +470,7 @@ fn test_at_block() { } for (bad_test, expected) in bad.iter() { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -483,7 +491,7 @@ fn test_trait_reference_unknown() { StacksEpochId::Epoch2_05, ) .unwrap_err(); - assert_eq!(expected, &res.err); + assert_eq!(*expected, *res.err); } } @@ -495,7 +503,7 @@ fn test_unexpected_use_of_field_or_trait_reference() { )]; for (bad_test, expected) in bad.iter() { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -516,12 +524,12 @@ fn test_simple_arithmetic_checks() { "(and (or true false) (+ 1 2 3))", ]; let bad_expected = [ - CheckErrors::TypeError(IntType, BoolType), + CheckErrors::TypeError(Box::new(IntType), Box::new(BoolType)), CheckErrors::RequiresAtLeastArguments(1, 0), CheckErrors::IncorrectArgumentCount(2, 1), CheckErrors::UndefinedVariable("x".to_string()), - CheckErrors::TypeError(IntType, BoolType), - CheckErrors::TypeError(BoolType, IntType), + CheckErrors::TypeError(Box::new(IntType), Box::new(BoolType)), + CheckErrors::TypeError(Box::new(BoolType), Box::new(IntType)), ]; for (good_test, expected) in good.iter().zip(expected.iter()) { @@ -532,7 +540,7 @@ fn test_simple_arithmetic_checks() { } for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -581,14 +589,14 @@ fn test_simple_hash_checks() { for bad_test in bad_types.iter() { assert!(matches!( - type_check_helper(bad_test).unwrap_err().err, + *type_check_helper(bad_test).unwrap_err().err, CheckErrors::UnionTypeError(_, _) )); } for bad_test in invalid_args.iter() { assert!(matches!( - type_check_helper(bad_test).unwrap_err().err, + *type_check_helper(bad_test).unwrap_err().err, CheckErrors::IncorrectArgumentCount(_, _) )); } @@ -612,10 +620,10 @@ fn test_simple_ifs() { ]; let bad_expected = [ - CheckErrors::IfArmsMustMatch(BoolType, IntType), - CheckErrors::IfArmsMustMatch(ascii_type(1), BoolType), + CheckErrors::IfArmsMustMatch(Box::new(BoolType), Box::new(IntType)), + CheckErrors::IfArmsMustMatch(Box::new(ascii_type(1)), Box::new(BoolType)), CheckErrors::IncorrectArgumentCount(3, 0), - CheckErrors::TypeError(BoolType, IntType), + CheckErrors::TypeError(Box::new(BoolType), Box::new(IntType)), ]; for (good_test, expected) in good.iter().zip(expected.iter()) { @@ -626,7 +634,7 @@ fn test_simple_ifs() { } for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -650,7 +658,10 @@ fn test_simple_lets() { let bad_expected = [ CheckErrors::BadSyntaxBinding, CheckErrors::BadSyntaxBinding, - CheckErrors::TypeError(TypeSignature::IntType, TypeSignature::UIntType), + CheckErrors::TypeError( + Box::new(TypeSignature::IntType), + Box::new(TypeSignature::UIntType), + ), ]; for (good_test, expected) in good.iter().zip(expected.iter()) { @@ -661,7 +672,7 @@ fn test_simple_lets() { } for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -702,19 +713,22 @@ fn test_index_of() { ]; let bad_expected = [ - CheckErrors::ExpectedSequence(TypeSignature::IntType), - CheckErrors::TypeError(TypeSignature::IntType, TypeSignature::UIntType), + CheckErrors::ExpectedSequence(Box::new(TypeSignature::IntType)), CheckErrors::TypeError( - TypeSignature::min_buffer().unwrap(), - TypeSignature::min_string_ascii().unwrap(), + Box::new(TypeSignature::IntType), + Box::new(TypeSignature::UIntType), ), CheckErrors::TypeError( - TypeSignature::min_string_utf8().unwrap(), - TypeSignature::min_string_ascii().unwrap(), + Box::new(TypeSignature::min_buffer().unwrap()), + Box::new(TypeSignature::min_string_ascii().unwrap()), ), CheckErrors::TypeError( - TypeSignature::min_string_ascii().unwrap(), - TypeSignature::min_string_utf8().unwrap(), + Box::new(TypeSignature::min_string_utf8().unwrap()), + Box::new(TypeSignature::min_string_ascii().unwrap()), + ), + CheckErrors::TypeError( + Box::new(TypeSignature::min_string_ascii().unwrap()), + Box::new(TypeSignature::min_string_utf8().unwrap()), ), CheckErrors::CouldNotDetermineType, CheckErrors::CouldNotDetermineType, @@ -722,7 +736,7 @@ fn test_index_of() { ]; for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -747,8 +761,11 @@ fn test_element_at() { let bad = ["(element-at (list 1 2 3 4 5) 100)", "(element-at 3 u100)"]; let bad_expected = [ - CheckErrors::TypeError(TypeSignature::UIntType, TypeSignature::IntType), - CheckErrors::ExpectedSequence(TypeSignature::IntType), + CheckErrors::TypeError( + Box::new(TypeSignature::UIntType), + Box::new(TypeSignature::IntType), + ), + CheckErrors::ExpectedSequence(Box::new(TypeSignature::IntType)), ]; for (good_test, expected) in good.iter().zip(expected.iter()) { @@ -759,7 +776,7 @@ fn test_element_at() { } for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -780,19 +797,22 @@ fn test_eqs() { ]; let bad_expected = [ - CheckErrors::TypeError(BoolType, IntType), - CheckErrors::TypeError(TypeSignature::list_of(IntType, 1).unwrap(), IntType), + CheckErrors::TypeError(Box::new(BoolType), Box::new(IntType)), + CheckErrors::TypeError( + Box::new(TypeSignature::list_of(IntType, 1).unwrap()), + Box::new(IntType), + ), CheckErrors::TypeError( - TypeSignature::from_string( + Box::new(TypeSignature::from_string( "(optional bool)", ClarityVersion::Clarity1, StacksEpochId::Epoch2_05, - ), - TypeSignature::from_string( + )), + Box::new(TypeSignature::from_string( "(optional int)", ClarityVersion::Clarity1, StacksEpochId::Epoch2_05, - ), + )), ), ]; @@ -804,7 +824,7 @@ fn test_eqs() { } for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -825,7 +845,7 @@ fn test_asserts() { let bad_expected = [ CheckErrors::IncorrectArgumentCount(2, 1), - CheckErrors::TypeError(BoolType, IntType), + CheckErrors::TypeError(Box::new(BoolType), Box::new(IntType)), CheckErrors::IncorrectArgumentCount(2, 3), ]; @@ -837,7 +857,7 @@ fn test_asserts() { } for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -890,23 +910,23 @@ fn test_lists() { "(map + (list 1 2 3 4 5) (list true true true true true))", ]; let bad_expected = [ - CheckErrors::TypeError(BoolType, IntType), + CheckErrors::TypeError(Box::new(BoolType), Box::new(IntType)), CheckErrors::IncorrectArgumentCount(1, 2), CheckErrors::IncorrectArgumentCount(1, 2), - CheckErrors::TypeError(IntType, BoolType), - CheckErrors::TypeError(IntType, BoolType), - CheckErrors::TypeError(IntType, BoolType), - CheckErrors::TypeError(BoolType, buff_type(20)), - CheckErrors::TypeError(BoolType, buff_type(20)), - CheckErrors::TypeError(BoolType, IntType), + CheckErrors::TypeError(Box::new(IntType), Box::new(BoolType)), + CheckErrors::TypeError(Box::new(IntType), Box::new(BoolType)), + CheckErrors::TypeError(Box::new(IntType), Box::new(BoolType)), + CheckErrors::TypeError(Box::new(BoolType), Box::new(buff_type(20))), + CheckErrors::TypeError(Box::new(BoolType), Box::new(buff_type(20))), + CheckErrors::TypeError(Box::new(BoolType), Box::new(IntType)), CheckErrors::IncorrectArgumentCount(2, 3), CheckErrors::UnknownFunction("ynot".to_string()), CheckErrors::IllegalOrUnknownFunctionApplication("if".to_string()), CheckErrors::IncorrectArgumentCount(2, 1), - CheckErrors::UnionTypeError(vec![IntType, UIntType], BoolType), - CheckErrors::ExpectedSequence(UIntType), - CheckErrors::ExpectedSequence(IntType), - CheckErrors::TypeError(IntType, BoolType), + CheckErrors::UnionTypeError(vec![IntType, UIntType], Box::new(BoolType)), + CheckErrors::ExpectedSequence(Box::new(UIntType)), + CheckErrors::ExpectedSequence(Box::new(IntType)), + CheckErrors::TypeError(Box::new(IntType), Box::new(BoolType)), ]; for (good_test, expected) in good.iter().zip(expected.iter()) { @@ -917,7 +937,7 @@ fn test_lists() { } for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -947,20 +967,20 @@ fn test_buff() { "(len 1)", ]; let bad_expected = [ - CheckErrors::TypeError(BoolType, IntType), + CheckErrors::TypeError(Box::new(BoolType), Box::new(IntType)), CheckErrors::IncorrectArgumentCount(1, 2), - CheckErrors::TypeError(IntType, BoolType), - CheckErrors::TypeError(IntType, BoolType), - CheckErrors::TypeError(IntType, BoolType), - CheckErrors::TypeError(BoolType, buff_type(20)), - CheckErrors::TypeError(BoolType, IntType), + CheckErrors::TypeError(Box::new(IntType), Box::new(BoolType)), + CheckErrors::TypeError(Box::new(IntType), Box::new(BoolType)), + CheckErrors::TypeError(Box::new(IntType), Box::new(BoolType)), + CheckErrors::TypeError(Box::new(BoolType), Box::new(buff_type(20))), + CheckErrors::TypeError(Box::new(BoolType), Box::new(IntType)), CheckErrors::IncorrectArgumentCount(2, 3), CheckErrors::UnknownFunction("ynot".to_string()), CheckErrors::IllegalOrUnknownFunctionApplication("if".to_string()), CheckErrors::IncorrectArgumentCount(2, 1), - CheckErrors::UnionTypeError(vec![IntType, UIntType], BoolType), - CheckErrors::ExpectedSequence(UIntType), - CheckErrors::ExpectedSequence(IntType), + CheckErrors::UnionTypeError(vec![IntType, UIntType], Box::new(BoolType)), + CheckErrors::ExpectedSequence(Box::new(UIntType)), + CheckErrors::ExpectedSequence(Box::new(IntType)), ]; for (good_test, expected) in good.iter().zip(expected.iter()) { @@ -971,7 +991,7 @@ fn test_buff() { } for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -1040,7 +1060,7 @@ fn test_native_as_max_len() { CheckErrors::ValueTooLarge, ]; for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -1081,12 +1101,12 @@ fn test_native_append() { ]; let bad_expected = [ - CheckErrors::TypeError(IntType, UIntType), - CheckErrors::TypeError(UIntType, IntType), + CheckErrors::TypeError(Box::new(IntType), Box::new(UIntType)), + CheckErrors::TypeError(Box::new(UIntType), Box::new(IntType)), CheckErrors::IncorrectArgumentCount(2, 1), ]; for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -1109,12 +1129,12 @@ fn test_native_concat() { ]; let bad_expected = [ - CheckErrors::TypeError(IntType, UIntType), - CheckErrors::TypeError(UIntType, IntType), + CheckErrors::TypeError(Box::new(IntType), Box::new(UIntType)), + CheckErrors::TypeError(Box::new(UIntType), Box::new(IntType)), CheckErrors::IncorrectArgumentCount(2, 1), ]; for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -1207,8 +1227,8 @@ fn test_tuples() { ]; let bad_expected = [ - CheckErrors::TypeError(IntType, BoolType), - CheckErrors::TypeError(BoolType, IntType), + CheckErrors::TypeError(Box::new(IntType), Box::new(BoolType)), + CheckErrors::TypeError(Box::new(BoolType), Box::new(IntType)), ]; for (good_test, expected) in good.iter().zip(expected.iter()) { @@ -1219,7 +1239,7 @@ fn test_tuples() { } for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -1231,7 +1251,7 @@ fn test_empty_tuple_should_fail() { "#; assert_eq!( - mem_type_check( + *mem_type_check( contract_src, ClarityVersion::Clarity1, StacksEpochId::Epoch2_05 @@ -1334,9 +1354,9 @@ fn test_simple_uints() { let bad = ["(> u1 1)", "(to-uint true)", "(to-int false)"]; let bad_expected = [ - CheckErrors::TypeError(UIntType, IntType), - CheckErrors::TypeError(IntType, BoolType), - CheckErrors::TypeError(UIntType, BoolType), + CheckErrors::TypeError(Box::new(UIntType), Box::new(IntType)), + CheckErrors::TypeError(Box::new(IntType), Box::new(BoolType)), + CheckErrors::TypeError(Box::new(UIntType), Box::new(BoolType)), ]; for (good_test, expected) in good.iter().zip(expected.iter()) { @@ -1353,10 +1373,10 @@ fn test_simple_uints() { for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { assert_eq!( - &mem_type_check(bad_test, ClarityVersion::Clarity1, StacksEpochId::Epoch2_05) + *expected, + *mem_type_check(bad_test, ClarityVersion::Clarity1, StacksEpochId::Epoch2_05) .unwrap_err() - .err, - expected + .err ); } } @@ -1398,14 +1418,14 @@ fn test_response_inference() { let bad_expected = [ CheckErrors::TypeError( - TypeSignature::from_string( + Box::new(TypeSignature::from_string( "(response bool int)", ClarityVersion::Clarity1, StacksEpochId::Epoch2_05, - ), - BoolType, + )), + Box::new(BoolType), ), - CheckErrors::ReturnTypesMustMatch(IntType, BoolType), + CheckErrors::ReturnTypesMustMatch(Box::new(IntType), Box::new(BoolType)), CheckErrors::CouldNotDetermineResponseOkType, ]; @@ -1423,10 +1443,10 @@ fn test_response_inference() { for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { assert_eq!( - &mem_type_check(bad_test, ClarityVersion::Clarity1, StacksEpochId::Epoch2_05) + *expected, + *mem_type_check(bad_test, ClarityVersion::Clarity1, StacksEpochId::Epoch2_05) .unwrap_err() - .err, - expected + .err ); } } @@ -1540,16 +1560,16 @@ fn test_options() { "; assert!( - match mem_type_check(contract, ClarityVersion::Clarity1, StacksEpochId::Epoch2_05) + match *mem_type_check(contract, ClarityVersion::Clarity1, StacksEpochId::Epoch2_05) .unwrap_err() .err { CheckErrors::TypeError(t1, t2) => { - t1 == TypeSignature::from_string( + *t1 == TypeSignature::from_string( "(optional bool)", ClarityVersion::Clarity1, StacksEpochId::Epoch2_05, - ) && t2 + ) && *t2 == TypeSignature::from_string( "(optional int)", ClarityVersion::Clarity1, @@ -1694,7 +1714,10 @@ fn test_missing_value_on_declaration_should_fail() { StacksEpochId::Epoch2_05, ) .unwrap_err(); - assert!(matches!(res.err, CheckErrors::IncorrectArgumentCount(_, _))); + assert!(matches!( + *res.err, + CheckErrors::IncorrectArgumentCount(_, _) + )); } #[test] @@ -1709,7 +1732,7 @@ fn test_mismatching_type_on_declaration_should_fail() { StacksEpochId::Epoch2_05, ) .unwrap_err(); - assert!(matches!(res.err, CheckErrors::TypeError(_, _))); + assert!(matches!(*res.err, CheckErrors::TypeError(_, _))); } #[test] @@ -1730,7 +1753,7 @@ fn test_mismatching_type_on_update_should_fail() { StacksEpochId::Epoch2_05, ) .unwrap_err(); - assert!(matches!(res.err, CheckErrors::TypeError(_, _))); + assert!(matches!(*res.err, CheckErrors::TypeError(_, _))); } #[test] @@ -1747,7 +1770,7 @@ fn test_direct_access_to_persisted_var_should_fail() { StacksEpochId::Epoch2_05, ) .unwrap_err(); - assert!(matches!(res.err, CheckErrors::UndefinedVariable(_))); + assert!(matches!(*res.err, CheckErrors::UndefinedVariable(_))); } #[test] @@ -1767,7 +1790,7 @@ fn test_data_var_shadowed_by_let_should_fail() { StacksEpochId::Epoch2_05, ) .unwrap_err(); - assert!(matches!(res.err, CheckErrors::NameAlreadyUsed(_))); + assert!(matches!(*res.err, CheckErrors::NameAlreadyUsed(_))); } #[test] @@ -1785,7 +1808,7 @@ fn test_mutating_unknown_data_var_should_fail() { StacksEpochId::Epoch2_05, ) .unwrap_err(); - assert!(matches!(res.err, CheckErrors::NoSuchDataVariable(_))); + assert!(matches!(*res.err, CheckErrors::NoSuchDataVariable(_))); } #[test] @@ -1801,7 +1824,7 @@ fn test_accessing_unknown_data_var_should_fail() { StacksEpochId::Epoch2_05, ) .unwrap_err(); - assert!(matches!(res.err, CheckErrors::NoSuchDataVariable(_))); + assert!(matches!(*res.err, CheckErrors::NoSuchDataVariable(_))); } #[test] @@ -1817,7 +1840,7 @@ fn test_let_shadowed_by_let_should_fail() { StacksEpochId::Epoch2_05, ) .unwrap_err(); - assert!(matches!(res.err, CheckErrors::NameAlreadyUsed(_))); + assert!(matches!(*res.err, CheckErrors::NameAlreadyUsed(_))); } #[test] @@ -1834,7 +1857,7 @@ fn test_let_shadowed_by_nested_let_should_fail() { StacksEpochId::Epoch2_05, ) .unwrap_err(); - assert!(matches!(res.err, CheckErrors::NameAlreadyUsed(_))); + assert!(matches!(*res.err, CheckErrors::NameAlreadyUsed(_))); } #[test] @@ -1852,7 +1875,7 @@ fn test_define_constant_shadowed_by_let_should_fail() { StacksEpochId::Epoch2_05, ) .unwrap_err(); - assert!(matches!(res.err, CheckErrors::NameAlreadyUsed(_))); + assert!(matches!(*res.err, CheckErrors::NameAlreadyUsed(_))); } #[test] @@ -1869,7 +1892,7 @@ fn test_define_constant_shadowed_by_argument_should_fail() { StacksEpochId::Epoch2_05, ) .unwrap_err(); - assert!(matches!(res.err, CheckErrors::NameAlreadyUsed(_))); + assert!(matches!(*res.err, CheckErrors::NameAlreadyUsed(_))); } #[test] @@ -2091,7 +2114,7 @@ fn test_fetch_entry_mismatching_type_signatures() { StacksEpochId::Epoch2_05, ) .unwrap_err(); - assert!(matches!(res.err, CheckErrors::TypeError(_, _))); + assert!(matches!(*res.err, CheckErrors::TypeError(_, _))); } } @@ -2111,7 +2134,7 @@ fn test_fetch_entry_unbound_variables() { StacksEpochId::Epoch2_05, ) .unwrap_err(); - assert!(matches!(res.err, CheckErrors::UndefinedVariable(_))); + assert!(matches!(*res.err, CheckErrors::UndefinedVariable(_))); } } @@ -2163,7 +2186,7 @@ fn test_insert_entry_mismatching_type_signatures() { StacksEpochId::Epoch2_05, ) .unwrap_err(); - assert!(matches!(res.err, CheckErrors::TypeError(_, _))); + assert!(matches!(*res.err, CheckErrors::TypeError(_, _))); } } @@ -2186,7 +2209,7 @@ fn test_insert_entry_unbound_variables() { StacksEpochId::Epoch2_05, ) .unwrap_err(); - assert!(matches!(res.err, CheckErrors::UndefinedVariable(_))); + assert!(matches!(*res.err, CheckErrors::UndefinedVariable(_))); } } @@ -2236,7 +2259,7 @@ fn test_delete_entry_mismatching_type_signatures() { StacksEpochId::Epoch2_05, ) .unwrap_err(); - assert!(matches!(res.err, CheckErrors::TypeError(_, _))); + assert!(matches!(*res.err, CheckErrors::TypeError(_, _))); } } @@ -2256,7 +2279,7 @@ fn test_delete_entry_unbound_variables() { StacksEpochId::Epoch2_05, ) .unwrap_err(); - assert!(matches!(res.err, CheckErrors::UndefinedVariable(_))); + assert!(matches!(*res.err, CheckErrors::UndefinedVariable(_))); } } @@ -2310,7 +2333,7 @@ fn test_set_entry_mismatching_type_signatures() { StacksEpochId::Epoch2_05, ) .unwrap_err(); - assert!(matches!(res.err, CheckErrors::TypeError(_, _))); + assert!(matches!(*res.err, CheckErrors::TypeError(_, _))); } } @@ -2333,7 +2356,7 @@ fn test_set_entry_unbound_variables() { StacksEpochId::Epoch2_05, ) .unwrap_err(); - assert!(matches!(res.err, CheckErrors::UndefinedVariable(_))); + assert!(matches!(*res.err, CheckErrors::UndefinedVariable(_))); } } @@ -2468,7 +2491,7 @@ fn test_buff_negative_len() { StacksEpochId::Epoch2_05, ) .unwrap_err(); - assert!(matches!(res.err, CheckErrors::BadSyntaxBinding)); + assert!(matches!(*res.err, CheckErrors::BadSyntaxBinding)); } #[test] @@ -2482,7 +2505,7 @@ fn test_string_ascii_negative_len() { StacksEpochId::Epoch2_05, ) .unwrap_err(); - assert!(matches!(res.err, CheckErrors::BadSyntaxBinding)); + assert!(matches!(*res.err, CheckErrors::BadSyntaxBinding)); } #[test] @@ -2496,5 +2519,5 @@ fn test_string_utf8_negative_len() { StacksEpochId::Epoch2_05, ) .unwrap_err(); - assert!(matches!(res.err, CheckErrors::BadSyntaxBinding)); + assert!(matches!(*res.err, CheckErrors::BadSyntaxBinding)); } diff --git a/clarity/src/vm/analysis/type_checker/v2_1/mod.rs b/clarity/src/vm/analysis/type_checker/v2_1/mod.rs index 21f3dfa98e1..9b42dd80983 100644 --- a/clarity/src/vm/analysis/type_checker/v2_1/mod.rs +++ b/clarity/src/vm/analysis/type_checker/v2_1/mod.rs @@ -193,7 +193,11 @@ impl FunctionType { if !admitted { return ( cost, - Err(CheckErrors::TypeError(expected_type.clone(), arg_type.clone()).into()), + Err(CheckErrors::TypeError( + Box::new(expected_type.clone()), + Box::new(arg_type.clone()), + ) + .into()), ); } (cost, Ok(None)) @@ -210,7 +214,7 @@ impl FunctionType { TypeSignature::UIntType => Ok(Some(TypeSignature::UIntType)), _ => Err(CheckErrors::UnionTypeError( vec![TypeSignature::IntType, TypeSignature::UIntType], - arg_type.clone(), + Box::new(arg_type.clone()), ) .into()), }; @@ -220,10 +224,11 @@ impl FunctionType { .ok_or_else(|| CheckErrors::Expects("Failed to set accumulated type for arg indices >= 1 in variadic arithmetic".into()).into()); let check_result = return_type.and_then(|return_type| { if arg_type != return_type { - Err( - CheckErrors::TypeError(return_type.clone(), arg_type.clone()) - .into(), + Err(CheckErrors::TypeError( + Box::new(return_type.clone()), + Box::new(arg_type.clone()), ) + .into()) } else { Ok(None) } @@ -287,8 +292,8 @@ impl FunctionType { analysis_typecheck_cost(accounting, expected_type, found_type)?; if !expected_type.admits_type(&StacksEpochId::Epoch21, found_type)? { return Err(CheckErrors::TypeError( - expected_type.clone(), - found_type.clone(), + Box::new(expected_type.clone()), + Box::new(found_type.clone()), ) .into()); } @@ -305,8 +310,8 @@ impl FunctionType { analysis_typecheck_cost(accounting, expected_type, found_type)?; if !expected_type.admits_type(&StacksEpochId::Epoch21, found_type)? { return Err(CheckErrors::TypeError( - expected_type.clone(), - found_type.clone(), + Box::new(expected_type.clone()), + Box::new(found_type.clone()), ) .into()); } @@ -322,7 +327,10 @@ impl FunctionType { return Ok(return_type.clone()); } } - Err(CheckErrors::UnionTypeError(arg_types.clone(), found_type.clone()).into()) + Err( + CheckErrors::UnionTypeError(arg_types.clone(), Box::new(found_type.clone())) + .into(), + ) } FunctionType::Binary(left_arg_sig, right_arg_sig, return_sig) => { check_argument_count(2, args)?; @@ -356,13 +364,17 @@ impl FunctionType { TypeSignature::UIntType => Ok(TypeSignature::UIntType), _ => Err(CheckErrors::UnionTypeError( vec![TypeSignature::IntType, TypeSignature::UIntType], - first.clone(), + Box::new(first.clone()), )), }?; for found_type in rest.iter() { analysis_typecheck_cost(accounting, &TypeSignature::IntType, found_type)?; if found_type != &return_type { - return Err(CheckErrors::TypeError(return_type, found_type.clone()).into()); + return Err(CheckErrors::TypeError( + Box::new(return_type.clone()), + Box::new(found_type.clone()), + ) + .into()); } } Ok(return_type) @@ -400,7 +412,7 @@ impl FunctionType { TypeSignature::max_string_utf8()?, TypeSignature::max_buffer()?, ], - first.clone(), + Box::new(first.clone()), ) .into()); } @@ -434,7 +446,11 @@ impl FunctionType { }; if !pair_of_types_matches { - return Err(CheckErrors::TypeError(first.clone(), second.clone()).into()); + return Err(CheckErrors::TypeError( + Box::new(first.clone()), + Box::new(second.clone()), + ) + .into()); } Ok(TypeSignature::BoolType) @@ -576,9 +592,11 @@ impl FunctionType { (expected_type, value) => { if !expected_type.admits(&StacksEpochId::Epoch21, value)? { let actual_type = TypeSignature::type_of(value)?; - return Err( - CheckErrors::TypeError(expected_type.clone(), actual_type).into() - ); + return Err(CheckErrors::TypeError( + Box::new(expected_type.clone()), + Box::new(actual_type.clone()), + ) + .into()); } } } @@ -613,9 +631,11 @@ fn check_function_arg_signature( FunctionArgSignature::Single(expected_type) => { analysis_typecheck_cost(cost_tracker, expected_type, actual_type)?; if !expected_type.admits_type(&StacksEpochId::Epoch21, actual_type)? { - return Err( - CheckErrors::TypeError(expected_type.clone(), actual_type.clone()).into(), - ); + return Err(CheckErrors::TypeError( + Box::new(expected_type.clone()), + Box::new(actual_type.clone()), + ) + .into()); } } FunctionArgSignature::Union(expected_types) => { @@ -630,7 +650,7 @@ fn check_function_arg_signature( if !admitted { return Err(CheckErrors::UnionTypeError( expected_types.clone(), - actual_type.clone(), + Box::new(actual_type.clone()), ) .into()); } @@ -710,15 +730,15 @@ pub fn clarity2_trait_check_trait_compliance( tracker, ) { return Err(CheckErrors::IncompatibleTrait( - expected_trait_identifier.clone(), - actual_trait_identifier.clone(), + Box::new(expected_trait_identifier.clone()), + Box::new(actual_trait_identifier.clone()), ) .into()); } } else { return Err(CheckErrors::IncompatibleTrait( - expected_trait_identifier.clone(), - actual_trait_identifier.clone(), + Box::new(expected_trait_identifier.clone()), + Box::new(actual_trait_identifier.clone()), ) .into()); } @@ -790,9 +810,11 @@ fn clarity2_inner_type_check_type( tracker, )?; } else { - return Err( - CheckErrors::TypeError(expected_type.clone(), actual_type.clone()).into(), - ); + return Err(CheckErrors::TypeError( + Box::new(expected_type.clone()), + Box::new(actual_type.clone()), + ) + .into()); } } ( @@ -800,9 +822,11 @@ fn clarity2_inner_type_check_type( TypeSignature::TupleType(expected_tuple_type), ) => { if expected_tuple_type.get_type_map().len() != atom_tuple_type.get_type_map().len() { - return Err( - CheckErrors::TypeError(expected_type.clone(), actual_type.clone()).into(), - ); + return Err(CheckErrors::TypeError( + Box::new(expected_type.clone()), + Box::new(actual_type.clone()), + ) + .into()); } for (name, expected_field_type) in expected_tuple_type.get_type_map() { @@ -819,8 +843,8 @@ fn clarity2_inner_type_check_type( } None => { return Err(CheckErrors::TypeError( - expected_type.clone(), - actual_type.clone(), + Box::new(expected_type.clone()), + Box::new(actual_type.clone()), ) .into()); } @@ -894,9 +918,11 @@ fn clarity2_inner_type_check_type( (TypeSignature::NoType, _) => (), (_, _) => { if !expected_type.admits_type(&StacksEpochId::Epoch21, actual_type)? { - return Err( - CheckErrors::TypeError(expected_type.clone(), actual_type.clone()).into(), - ); + return Err(CheckErrors::TypeError( + Box::new(expected_type.clone()), + Box::new(actual_type.clone()), + ) + .into()); } } } @@ -1047,7 +1073,12 @@ impl<'a, 'b> TypeChecker<'a, 'b> { &expected_type, &return_type, ) - .map_err(|_| CheckErrors::ReturnTypesMustMatch(expected_type, return_type))?, + .map_err(|_| { + CheckErrors::ReturnTypesMustMatch( + Box::new(expected_type), + Box::new(return_type), + ) + })?, None => return_type, }; @@ -1216,9 +1247,10 @@ impl<'a, 'b> TypeChecker<'a, 'b> { } } if let Err(mut check_error) = check_result { - if let CheckErrors::IncorrectArgumentCount(expected, _actual) = check_error.err { - check_error.err = CheckErrors::IncorrectArgumentCount(expected, args.len()); - check_error.diagnostic = Diagnostic::err(&check_error.err) + if let CheckErrors::IncorrectArgumentCount(expected, _actual) = *check_error.err { + check_error.err = + Box::new(CheckErrors::IncorrectArgumentCount(expected, args.len())); + check_error.diagnostic = Diagnostic::err(check_error.err.as_ref()); } // accumulate the checking costs // the reason we do this now (instead of within the loop) is for backwards compatibility @@ -1311,7 +1343,10 @@ impl<'a, 'b> TypeChecker<'a, 'b> { &return_type, ) .map_err(|_| { - CheckErrors::ReturnTypesMustMatch(expected.clone(), return_type) + CheckErrors::ReturnTypesMustMatch( + Box::new(expected.clone()), + Box::new(return_type), + ) })? } else { return_type @@ -1478,8 +1513,11 @@ impl<'a, 'b> TypeChecker<'a, 'b> { analysis_typecheck_cost(self, expected_type, &actual_type)?; if !expected_type.admits_type(&StacksEpochId::Epoch21, &actual_type)? { - let mut err: CheckError = - CheckErrors::TypeError(expected_type.clone(), actual_type).into(); + let mut err: CheckError = CheckErrors::TypeError( + Box::new(expected_type.clone()), + Box::new(actual_type.clone()), + ) + .into(); err.set_expression(expr); Err(err) } else { @@ -1672,9 +1710,10 @@ impl<'a, 'b> TypeChecker<'a, 'b> { .add_public_function_type(f_name, FunctionType::Fixed(f_type))?; return Ok(Some(())); } else { - return Err( - CheckErrors::PublicFunctionMustReturnResponse(f_type.returns).into(), - ); + return Err(CheckErrors::PublicFunctionMustReturnResponse(Box::new( + f_type.returns, + )) + .into()); } } DefineFunctionsParsed::ReadOnlyFunction { signature, body } => { diff --git a/clarity/src/vm/analysis/type_checker/v2_1/natives/maps.rs b/clarity/src/vm/analysis/type_checker/v2_1/natives/maps.rs index 676badd14f1..84263a9b252 100644 --- a/clarity/src/vm/analysis/type_checker/v2_1/natives/maps.rs +++ b/clarity/src/vm/analysis/type_checker/v2_1/natives/maps.rs @@ -56,8 +56,8 @@ pub fn check_special_fetch_entry( if !expected_key_type.admits_type(&StacksEpochId::Epoch21, &key_type)? { Err(CheckError::new(CheckErrors::TypeError( - expected_key_type.clone(), - key_type, + Box::new(expected_key_type.clone()), + Box::new(key_type), ))) } else { Ok(option_type) @@ -89,8 +89,8 @@ pub fn check_special_delete_entry( if !expected_key_type.admits_type(&StacksEpochId::Epoch21, &key_type)? { Err(CheckError::new(CheckErrors::TypeError( - expected_key_type.clone(), - key_type, + Box::new(expected_key_type.clone()), + Box::new(key_type), ))) } else { Ok(TypeSignature::BoolType) @@ -130,13 +130,13 @@ fn check_set_or_insert_entry( if !expected_key_type.admits_type(&StacksEpochId::Epoch21, &key_type)? { Err(CheckError::new(CheckErrors::TypeError( - expected_key_type.clone(), - key_type, + Box::new(expected_key_type.clone()), + Box::new(key_type), ))) } else if !expected_value_type.admits_type(&StacksEpochId::Epoch21, &value_type)? { Err(CheckError::new(CheckErrors::TypeError( - expected_value_type.clone(), - value_type, + Box::new(expected_value_type.clone()), + Box::new(value_type), ))) } else { Ok(TypeSignature::BoolType) diff --git a/clarity/src/vm/analysis/type_checker/v2_1/natives/mod.rs b/clarity/src/vm/analysis/type_checker/v2_1/natives/mod.rs index 500632f0ddd..d28a8112ccd 100644 --- a/clarity/src/vm/analysis/type_checker/v2_1/natives/mod.rs +++ b/clarity/src/vm/analysis/type_checker/v2_1/natives/mod.rs @@ -178,10 +178,10 @@ fn check_special_get( let option_type = TypeSignature::new_option(inner_type)?; Ok(option_type) } else { - Err(CheckErrors::ExpectedTuple(*value_type_sig).into()) + Err(CheckErrors::ExpectedTuple(value_type_sig).into()) } } else { - Err(CheckErrors::ExpectedTuple(argument_type).into()) + Err(CheckErrors::ExpectedTuple(Box::new(argument_type)).into()) } } @@ -195,13 +195,13 @@ fn check_special_merge( let res = checker.type_check(&args[0], context)?; let mut base = match res { TypeSignature::TupleType(tuple_sig) => Ok(tuple_sig), - _ => Err(CheckErrors::ExpectedTuple(res.clone())), + _ => Err(CheckErrors::ExpectedTuple(Box::new(res.clone()))), }?; let res = checker.type_check(&args[1], context)?; let mut update = match res { TypeSignature::TupleType(tuple_sig) => Ok(tuple_sig), - _ => Err(CheckErrors::ExpectedTuple(res.clone())), + _ => Err(CheckErrors::ExpectedTuple(Box::new(res.clone()))), }?; runtime_cost( ClarityCostFunction::AnalysisCheckTupleMerge, @@ -363,8 +363,8 @@ fn check_special_set_var( if !expected_value_type.admits_type(&StacksEpochId::Epoch21, &value_type)? { Err(CheckError::new(CheckErrors::TypeError( - expected_value_type.clone(), - value_type, + Box::new(expected_value_type.clone()), + Box::new(value_type), ))) } else { Ok(TypeSignature::BoolType) @@ -391,7 +391,7 @@ fn check_special_equals( costs.push(cost); arg_type = Some( TypeSignature::least_supertype(&StacksEpochId::Epoch21, &x_type, &cur_type) - .map_err(|_| CheckErrors::TypeError(x_type, cur_type)), + .map_err(|_| CheckErrors::TypeError(Box::new(x_type), Box::new(cur_type))), ); } } @@ -426,7 +426,9 @@ fn check_special_if( TypeSignature::least_supertype(&StacksEpochId::Epoch21, expr1, expr2) .and_then(|t| t.concretize()) - .map_err(|_| CheckErrors::IfArmsMustMatch(expr1.clone(), expr2.clone()).into()) + .map_err(|_| { + CheckErrors::IfArmsMustMatch(Box::new(expr1.clone()), Box::new(expr2.clone())).into() + }) } fn check_contract_call( @@ -555,7 +557,9 @@ fn check_contract_call( } Some(var_type) => { // Any other typed constant is an error - return Err(CheckErrors::ExpectedCallableType(var_type.clone()).into()); + return Err( + CheckErrors::ExpectedCallableType(Box::new(var_type.clone())).into(), + ); } _ => { // Dynamic dispatch diff --git a/clarity/src/vm/analysis/type_checker/v2_1/natives/options.rs b/clarity/src/vm/analysis/type_checker/v2_1/natives/options.rs index 6b9469f970b..23217abeeae 100644 --- a/clarity/src/vm/analysis/type_checker/v2_1/natives/options.rs +++ b/clarity/src/vm/analysis/type_checker/v2_1/natives/options.rs @@ -82,7 +82,7 @@ pub fn check_special_is_response( if let TypeSignature::ResponseType(_types) = input { Ok(TypeSignature::BoolType) } else { - Err(CheckErrors::ExpectedResponseType(input.clone()).into()) + Err(CheckErrors::ExpectedResponseType(Box::new(input.clone())).into()) } } @@ -100,7 +100,7 @@ pub fn check_special_is_optional( if let TypeSignature::OptionalType(_type) = input { Ok(TypeSignature::BoolType) } else { - Err(CheckErrors::ExpectedOptionalType(input.clone()).into()) + Err(CheckErrors::ExpectedOptionalType(Box::new(input.clone())).into()) } } @@ -118,10 +118,14 @@ pub fn check_special_default_to( if let TypeSignature::OptionalType(input_type) = input { let contained_type = *input_type; - TypeSignature::least_supertype(&StacksEpochId::Epoch21, &default, &contained_type) - .map_err(|_| CheckErrors::DefaultTypesMustMatch(default, contained_type).into()) + TypeSignature::least_supertype(&StacksEpochId::Epoch21, &default, &contained_type).map_err( + |_| { + CheckErrors::DefaultTypesMustMatch(Box::new(default), Box::new(contained_type)) + .into() + }, + ) } else { - Err(CheckErrors::ExpectedOptionalType(input).into()) + Err(CheckErrors::ExpectedOptionalType(Box::new(input)).into()) } } @@ -159,7 +163,7 @@ fn inner_unwrap(input: TypeSignature, checker: &mut TypeChecker) -> TypeResult { Ok(ok_type) } } - _ => Err(CheckErrors::ExpectedOptionalOrResponseType(input).into()), + _ => Err(CheckErrors::ExpectedOptionalOrResponseType(Box::new(input)).into()), } } @@ -174,7 +178,7 @@ fn inner_unwrap_err(input: TypeSignature, checker: &mut TypeChecker) -> TypeResu Ok(err_type) } } else { - Err(CheckErrors::ExpectedResponseType(input).into()) + Err(CheckErrors::ExpectedResponseType(Box::new(input)).into()) } } @@ -242,7 +246,7 @@ pub fn check_special_try_ret( Ok(ok_type) } } - _ => Err(CheckErrors::ExpectedOptionalOrResponseType(input).into()), + _ => Err(CheckErrors::ExpectedOptionalOrResponseType(Box::new(input)).into()), } } @@ -341,7 +345,10 @@ fn check_special_match_opt( &some_branch_type, &none_branch_type, ) - .map_err(|_| CheckErrors::MatchArmsMustMatch(some_branch_type, none_branch_type).into()) + .map_err(|_| { + CheckErrors::MatchArmsMustMatch(Box::new(some_branch_type), Box::new(none_branch_type)) + .into() + }) } fn check_special_match_resp( @@ -380,7 +387,10 @@ fn check_special_match_resp( analysis_typecheck_cost(checker, &ok_branch_type, &err_branch_type)?; TypeSignature::least_supertype(&StacksEpochId::Epoch21, &ok_branch_type, &err_branch_type) - .map_err(|_| CheckErrors::MatchArmsMustMatch(ok_branch_type, err_branch_type).into()) + .map_err(|_| { + CheckErrors::MatchArmsMustMatch(Box::new(ok_branch_type), Box::new(err_branch_type)) + .into() + }) } pub fn check_special_match( @@ -399,6 +409,6 @@ pub fn check_special_match( TypeSignature::ResponseType(resp_type) => { check_special_match_resp(*resp_type, checker, &args[1..], context) } - _ => Err(CheckErrors::BadMatchInput(input).into()), + _ => Err(CheckErrors::BadMatchInput(Box::new(input)).into()), } } diff --git a/clarity/src/vm/analysis/type_checker/v2_1/natives/sequences.rs b/clarity/src/vm/analysis/type_checker/v2_1/natives/sequences.rs index 0207fe49d86..ae51b4429a6 100644 --- a/clarity/src/vm/analysis/type_checker/v2_1/natives/sequences.rs +++ b/clarity/src/vm/analysis/type_checker/v2_1/natives/sequences.rs @@ -104,7 +104,7 @@ pub fn check_special_map( // However that could lead to confusions when combining certain types: // ex: (map concat (list "hello " "hi ") "world") would fail, because // strings are handled as sequences. - return Err(CheckErrors::ExpectedSequence(argument_type).into()); + return Err(CheckErrors::ExpectedSequence(Box::new(argument_type)).into()); } }; @@ -134,10 +134,12 @@ pub fn check_special_map( } if let Err(mut check_error) = check_result { - if let CheckErrors::IncorrectArgumentCount(expected, _actual) = check_error.err { - check_error.err = - CheckErrors::IncorrectArgumentCount(expected, args.len().saturating_sub(1)); - check_error.diagnostic = Diagnostic::err(&check_error.err) + if let CheckErrors::IncorrectArgumentCount(expected, _actual) = *check_error.err { + check_error.err = Box::new(CheckErrors::IncorrectArgumentCount( + expected, + args.len().saturating_sub(1), + )); + check_error.diagnostic = Diagnostic::err(check_error.err.as_ref()); } // accumulate the checking costs for cost in total_costs.into_iter() { @@ -177,7 +179,9 @@ pub fn check_special_filter( { let input_type = match argument_type { TypeSignature::SequenceType(ref sequence_type) => Ok(sequence_type.unit_type()?), - _ => Err(CheckErrors::ExpectedSequence(argument_type.clone())), + _ => Err(CheckErrors::ExpectedSequence(Box::new( + argument_type.clone(), + ))), }?; let filter_type = function_type.check_args( @@ -188,7 +192,11 @@ pub fn check_special_filter( )?; if TypeSignature::BoolType != filter_type { - return Err(CheckErrors::TypeError(TypeSignature::BoolType, filter_type).into()); + return Err(CheckErrors::TypeError( + Box::new(TypeSignature::BoolType), + Box::new(filter_type), + ) + .into()); } } @@ -214,7 +222,7 @@ pub fn check_special_fold( let input_type = match argument_type { TypeSignature::SequenceType(sequence_type) => Ok(sequence_type.unit_type()?), - _ => Err(CheckErrors::ExpectedSequence(argument_type)), + _ => Err(CheckErrors::ExpectedSequence(Box::new(argument_type))), }?; let initial_value_type = checker.type_check(&args[2], context)?; @@ -294,11 +302,15 @@ pub fn check_special_concat( TypeSignature::SequenceType(StringType(UTF8(size.try_into()?))) } (_, _) => { - return Err(CheckErrors::TypeError(lhs_type.clone(), rhs_type.clone()).into()) + return Err(CheckErrors::TypeError( + Box::new(lhs_type.clone()), + Box::new(rhs_type.clone()), + ) + .into()) } } } - _ => return Err(CheckErrors::ExpectedSequence(lhs_type.clone()).into()), + _ => return Err(CheckErrors::ExpectedSequence(Box::new(lhs_type.clone())).into()), }; Ok(res) } @@ -346,7 +358,11 @@ pub fn check_special_as_max_len( SymbolicExpressionType::LiteralValue(Value::UInt(expected_len)) => expected_len, _ => { let expected_len_type = checker.type_check(&args[1], context)?; - return Err(CheckErrors::TypeError(TypeSignature::UIntType, expected_len_type).into()); + return Err(CheckErrors::TypeError( + Box::new(TypeSignature::UIntType), + Box::new(expected_len_type), + ) + .into()); } }; runtime_cost( @@ -384,7 +400,7 @@ pub fn check_special_as_max_len( StringUTF8Length::try_from(expected_len)?, )))), )), - _ => Err(CheckErrors::ExpectedSequence(sequence).into()), + _ => Err(CheckErrors::ExpectedSequence(Box::new(sequence)).into()), } } @@ -400,7 +416,7 @@ pub fn check_special_len( match collection_type { TypeSignature::SequenceType(_) => Ok(()), - _ => Err(CheckErrors::ExpectedSequence(collection_type)), + _ => Err(CheckErrors::ExpectedSequence(Box::new(collection_type))), }?; Ok(TypeSignature::UIntType) @@ -438,7 +454,7 @@ pub fn check_special_element_at( .map_err(|_| CheckErrors::Expects("Bad constructor".into()))?, )))), )), - _ => Err(CheckErrors::ExpectedSequence(collection_type).into()), + _ => Err(CheckErrors::ExpectedSequence(Box::new(collection_type)).into()), } } @@ -454,7 +470,7 @@ pub fn check_special_index_of( let expected_input_type = match list_type { TypeSignature::SequenceType(ref sequence_type) => Ok(sequence_type.unit_type()?), - _ => Err(CheckErrors::ExpectedSequence(list_type)), + _ => Err(CheckErrors::ExpectedSequence(Box::new(list_type))), }?; checker.type_check_expects(&args[1], context, &expected_input_type)?; @@ -477,7 +493,7 @@ pub fn check_special_slice( TypeSignature::SequenceType(seq) => { TypeSignature::new_option(TypeSignature::SequenceType(seq))? } - _ => return Err(CheckErrors::ExpectedSequence(seq_type).into()), + _ => return Err(CheckErrors::ExpectedSequence(Box::new(seq_type)).into()), }; // Check left position argument @@ -501,7 +517,7 @@ pub fn check_special_replace_at( let input_type = checker.type_check(&args[0], context)?; let seq_type = match &input_type { TypeSignature::SequenceType(seq) => seq, - _ => return Err(CheckErrors::ExpectedSequence(input_type).into()), + _ => return Err(CheckErrors::ExpectedSequence(Box::new(input_type)).into()), }; let unit_seq = seq_type.unit_type()?; // Check index argument diff --git a/clarity/src/vm/analysis/type_checker/v2_1/tests/assets.rs b/clarity/src/vm/analysis/type_checker/v2_1/tests/assets.rs index 8f766f87123..a25a43a3cc5 100644 --- a/clarity/src/vm/analysis/type_checker/v2_1/tests/assets.rs +++ b/clarity/src/vm/analysis/type_checker/v2_1/tests/assets.rs @@ -176,42 +176,108 @@ fn test_bad_asset_usage() { CheckErrors::NoSuchFT("stackoos".to_string()), CheckErrors::BadTokenName, CheckErrors::BadTokenName, - CheckErrors::TypeError(TypeSignature::PrincipalType, TypeSignature::UIntType), - CheckErrors::TypeError(TypeSignature::PrincipalType, TypeSignature::IntType), + CheckErrors::TypeError( + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::UIntType), + ), + CheckErrors::TypeError( + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::IntType), + ), CheckErrors::BadTokenName, CheckErrors::NoSuchNFT("stackoos".to_string()), - CheckErrors::TypeError(string_ascii_type(10), TypeSignature::UIntType), - CheckErrors::TypeError(string_ascii_type(10), string_ascii_type(15)), + CheckErrors::TypeError( + Box::new(string_ascii_type(10)), + Box::new(TypeSignature::UIntType), + ), + CheckErrors::TypeError( + Box::new(string_ascii_type(10)), + Box::new(string_ascii_type(15)), + ), CheckErrors::BadTokenName, CheckErrors::NoSuchNFT("stackoos".to_string()), - CheckErrors::TypeError(string_ascii_type(10), TypeSignature::UIntType), - CheckErrors::TypeError(string_ascii_type(10), string_ascii_type(15)), - CheckErrors::TypeError(TypeSignature::PrincipalType, TypeSignature::UIntType), + CheckErrors::TypeError( + Box::new(string_ascii_type(10)), + Box::new(TypeSignature::UIntType), + ), + CheckErrors::TypeError( + Box::new(string_ascii_type(10)), + Box::new(string_ascii_type(15)), + ), + CheckErrors::TypeError( + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::UIntType), + ), CheckErrors::NoSuchFT("stackoos".to_string()), CheckErrors::BadTokenName, - CheckErrors::TypeError(TypeSignature::PrincipalType, TypeSignature::UIntType), - CheckErrors::TypeError(TypeSignature::UIntType, TypeSignature::BoolType), + CheckErrors::TypeError( + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::UIntType), + ), + CheckErrors::TypeError( + Box::new(TypeSignature::UIntType), + Box::new(TypeSignature::BoolType), + ), CheckErrors::BadTokenName, CheckErrors::NoSuchNFT("stackoos".to_string()), - CheckErrors::TypeError(TypeSignature::PrincipalType, TypeSignature::UIntType), - CheckErrors::TypeError(TypeSignature::PrincipalType, TypeSignature::UIntType), - CheckErrors::TypeError(string_ascii_type(10), TypeSignature::UIntType), + CheckErrors::TypeError( + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::UIntType), + ), + CheckErrors::TypeError( + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::UIntType), + ), + CheckErrors::TypeError( + Box::new(string_ascii_type(10)), + Box::new(TypeSignature::UIntType), + ), CheckErrors::BadTokenName, - CheckErrors::TypeError(string_ascii_type(10), TypeSignature::UIntType), - CheckErrors::TypeError(TypeSignature::PrincipalType, TypeSignature::UIntType), + CheckErrors::TypeError( + Box::new(string_ascii_type(10)), + Box::new(TypeSignature::UIntType), + ), + CheckErrors::TypeError( + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::UIntType), + ), CheckErrors::NoSuchFT("stackoos".to_string()), CheckErrors::BadTokenName, - CheckErrors::TypeError(TypeSignature::PrincipalType, TypeSignature::UIntType), - CheckErrors::TypeError(TypeSignature::UIntType, TypeSignature::BoolType), - CheckErrors::TypeError(TypeSignature::PrincipalType, TypeSignature::UIntType), - CheckErrors::TypeError(TypeSignature::UIntType, TypeSignature::BoolType), + CheckErrors::TypeError( + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::UIntType), + ), + CheckErrors::TypeError( + Box::new(TypeSignature::UIntType), + Box::new(TypeSignature::BoolType), + ), + CheckErrors::TypeError( + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::UIntType), + ), + CheckErrors::TypeError( + Box::new(TypeSignature::UIntType), + Box::new(TypeSignature::BoolType), + ), CheckErrors::DefineNFTBadSignature, - CheckErrors::TypeError(TypeSignature::UIntType, TypeSignature::IntType), - CheckErrors::TypeError(TypeSignature::UIntType, TypeSignature::IntType), + CheckErrors::TypeError( + Box::new(TypeSignature::UIntType), + Box::new(TypeSignature::IntType), + ), + CheckErrors::TypeError( + Box::new(TypeSignature::UIntType), + Box::new(TypeSignature::IntType), + ), CheckErrors::NoSuchFT("stackoos".to_string()), CheckErrors::NoSuchFT("stackoos".to_string()), - CheckErrors::TypeError(TypeSignature::UIntType, TypeSignature::IntType), - CheckErrors::TypeError(TypeSignature::PrincipalType, TypeSignature::IntType), + CheckErrors::TypeError( + Box::new(TypeSignature::UIntType), + Box::new(TypeSignature::IntType), + ), + CheckErrors::TypeError( + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::IntType), + ), ]; for (script, expected_err) in bad_scripts.iter().zip(expected.iter()) { @@ -223,6 +289,6 @@ fn test_bad_asset_usage() { ) .unwrap_err(); println!("{script}"); - assert_eq!(&actual_err.err, expected_err); + assert_eq!(*actual_err.err, *expected_err); } } diff --git a/clarity/src/vm/analysis/type_checker/v2_1/tests/contracts.rs b/clarity/src/vm/analysis/type_checker/v2_1/tests/contracts.rs index f4955c8ac1e..f56080bbdb8 100644 --- a/clarity/src/vm/analysis/type_checker/v2_1/tests/contracts.rs +++ b/clarity/src/vm/analysis/type_checker/v2_1/tests/contracts.rs @@ -80,7 +80,7 @@ pub fn type_check_version( version, false, ) - .map_err(|(e, _)| e) + .map_err(|e| e.0) } const SIMPLE_TOKENS: &str = "(define-map tokens { account: principal } { balance: uint }) @@ -489,7 +489,7 @@ fn test_names_tokens_contracts_bad(#[case] version: ClarityVersion, #[case] epoc let err = db .execute(|db| type_check(&names_contract_id, &mut names_contract, db, true)) .unwrap_err(); - assert!(matches!(err.err, CheckErrors::TypeError(_, _))); + assert!(matches!(*err.err, CheckErrors::TypeError(_, _))); } #[test] @@ -530,11 +530,11 @@ fn test_bad_map_usage() { for contract in tests.iter() { let err = mem_type_check(contract).unwrap_err(); - assert!(matches!(err.err, CheckErrors::TypeError(_, _))); + assert!(matches!(*err.err, CheckErrors::TypeError(_, _))); } assert!(matches!( - mem_type_check(unhandled_option).unwrap_err().err, + *mem_type_check(unhandled_option).unwrap_err().err, CheckErrors::UnionTypeError(_, _) )); } @@ -622,24 +622,24 @@ fn test_expects() { for unmatched_return_types in bad_return_types_tests.iter() { let err = mem_type_check(unmatched_return_types).unwrap_err(); eprintln!("unmatched_return_types returned check error: {err}"); - assert!(matches!(err.err, CheckErrors::ReturnTypesMustMatch(_, _))); + assert!(matches!(*err.err, CheckErrors::ReturnTypesMustMatch(_, _))); } let err = mem_type_check(bad_default_type).unwrap_err(); eprintln!("bad_default_types returned check error: {err}"); - assert!(matches!(err.err, CheckErrors::DefaultTypesMustMatch(_, _))); + assert!(matches!(*err.err, CheckErrors::DefaultTypesMustMatch(_, _))); let err = mem_type_check(notype_response_type).unwrap_err(); eprintln!("notype_response_type returned check error: {err}"); assert!(matches!( - err.err, + *err.err, CheckErrors::CouldNotDetermineResponseErrType )); let err = mem_type_check(notype_response_type_2).unwrap_err(); eprintln!("notype_response_type_2 returned check error: {err}"); assert!(matches!( - err.err, + *err.err, CheckErrors::CouldNotDetermineResponseOkType )); } @@ -675,26 +675,19 @@ fn test_trait_to_compatible_trait() { mem_type_check(trait_to_compatible_trait).unwrap(); let err = mem_type_check_v1(trait_to_compatible_trait).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::TypeError(expected, found), - expressions: _, - diagnostic: _, - } => { - match (expected, found) { - ( - TypeSignature::CallableType(CallableSubtype::Trait(expected_trait)), - TypeSignature::CallableType(CallableSubtype::Trait(found_trait)), - ) => { - assert_eq!(expected_trait.name.as_str(), "trait-2"); - assert_eq!(found_trait.name.as_str(), "trait-1"); - true - } - _ => false, + match *err.err { + CheckErrors::TypeError(expected, found) => match (&*expected, &*found) { + ( + TypeSignature::CallableType(CallableSubtype::Trait(expected_trait)), + TypeSignature::CallableType(CallableSubtype::Trait(found_trait)), + ) => { + assert_eq!(expected_trait.name.as_str(), "trait-2"); + assert_eq!(found_trait.name.as_str(), "trait-1"); } - } - _ => false, - }); + _ => panic!("Unexpected type signatures: {expected:?} {found:?}"), + }, + _ => panic!("Unexpected error: {err:?}"), + }; } /// Pass a principal to a trait parameter @@ -709,45 +702,31 @@ fn test_bad_principal_to_trait() { (contract-call? contract get-1 u1))"; let err = mem_type_check(bad_principal_to_trait).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::TypeError(expected, found), - expressions: _, - diagnostic: _, - } => { - match (expected, found) { - ( - TypeSignature::CallableType(CallableSubtype::Trait(expected_trait)), - TypeSignature::PrincipalType, - ) => { - assert_eq!(expected_trait.name.as_str(), "trait-1"); - true - } - _ => false, + match *err.err { + CheckErrors::TypeError(expected, found) => match (&*expected, &*found) { + ( + TypeSignature::CallableType(CallableSubtype::Trait(expected_trait)), + TypeSignature::PrincipalType, + ) => { + assert_eq!(expected_trait.name.as_str(), "trait-1"); } - } - _ => false, - }); + _ => panic!("Unexpected type signatures: {expected:?} {found:?}"), + }, + _ => panic!("Unexpected error: {err:?}"), + }; let err = mem_type_check_v1(bad_principal_to_trait).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::TypeError(expected, found), - expressions: _, - diagnostic: _, - } => { - match (expected, found) { - ( - TypeSignature::CallableType(CallableSubtype::Trait(expected_trait)), - TypeSignature::PrincipalType, - ) => { - assert_eq!(expected_trait.name.as_str(), "trait-1"); - true - } - _ => false, + match *err.err { + CheckErrors::TypeError(expected, found) => match (&*expected, &*found) { + ( + TypeSignature::CallableType(CallableSubtype::Trait(expected_trait)), + TypeSignature::PrincipalType, + ) => { + assert_eq!(expected_trait.name.as_str(), "trait-1"); } - } - _ => false, - }); + _ => panic!("Unexpected type signatures: {expected:?} {found:?}"), + }, + _ => panic!("Unexpected error: {err:?}"), + }; } /// Pass a trait to a trait parameter which is not compatible @@ -765,39 +744,27 @@ fn test_bad_other_trait() { (contract-call? contract get-2 u1))"; let err = mem_type_check(bad_other_trait).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::IncompatibleTrait(expected, actual), - expressions: _, - diagnostic: _, - } => { + match *err.err { + CheckErrors::IncompatibleTrait(expected, actual) => { assert_eq!(expected.name.as_str(), "trait-2"); assert_eq!(actual.name.as_str(), "trait-1"); - true } - _ => false, - }); + _ => panic!("Unexpected error: {err:?}"), + }; let err = mem_type_check_v1(bad_other_trait).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::TypeError(expected, found), - expressions: _, - diagnostic: _, - } => { - match (expected, found) { - ( - TypeSignature::CallableType(CallableSubtype::Trait(expected_trait)), - TypeSignature::CallableType(CallableSubtype::Trait(found_trait)), - ) => { - assert_eq!(expected_trait.name.as_str(), "trait-2"); - assert_eq!(found_trait.name.as_str(), "trait-1"); - true - } - _ => false, + match *err.err { + CheckErrors::TypeError(expected, actual) => match (&*expected, &*actual) { + ( + TypeSignature::CallableType(CallableSubtype::Trait(expected_trait)), + TypeSignature::CallableType(CallableSubtype::Trait(found_trait)), + ) => { + assert_eq!(expected_trait.name.as_str(), "trait-2"); + assert_eq!(found_trait.name.as_str(), "trait-1"); } - } - _ => false, - }); + _ => panic!("Unexpected type signatures: {expected:?} {actual:?}"), + }, + _ => panic!("Unexpected error: {err:?}"), + }; } /// Pass a trait embedded in a compound type @@ -818,17 +785,12 @@ fn test_embedded_trait() { mem_type_check(embedded_trait).unwrap(); let err = mem_type_check_v1(embedded_trait).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::TraitReferenceUnknown(name), - expressions: _, - diagnostic: _, - } => { + match *err.err { + CheckErrors::TraitReferenceUnknown(name) => { assert_eq!(name.as_str(), "contract"); - true } - _ => false, - }); + _ => panic!("Unexpected error: {err:?}"), + }; } /// Pass a trait embedded in a compound type to a parameter with a compatible @@ -853,17 +815,12 @@ fn test_embedded_trait_compatible() { mem_type_check(embedded_trait_compatible).unwrap(); let err = mem_type_check_v1(embedded_trait_compatible).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::TraitReferenceUnknown(name), - expressions: _, - diagnostic: _, - } => { + match *err.err { + CheckErrors::TraitReferenceUnknown(name) => { assert_eq!(name.as_str(), "contract"); - true } - _ => false, - }); + _ => panic!("Unexpected error: {err:?}"), + }; } /// Pass a trait embedded in a compound type to a parameter with an @@ -891,30 +848,20 @@ fn test_bad_embedded_trait() { )"; let err = mem_type_check(bad_embedded_trait).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::IncompatibleTrait(expected, actual), - expressions: _, - diagnostic: _, - } => { + match *err.err { + CheckErrors::IncompatibleTrait(expected, actual) => { assert_eq!(expected.name.as_str(), "trait-12"); assert_eq!(actual.name.as_str(), "trait-1"); - true } - _ => false, - }); + _ => panic!("Unexpected error: {err:?}"), + }; let err = mem_type_check_v1(bad_embedded_trait).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::TraitReferenceUnknown(name), - expressions: _, - diagnostic: _, - } => { + match *err.err { + CheckErrors::TraitReferenceUnknown(name) => { assert_eq!(name.as_str(), "contract"); - true } - _ => false, - }); + _ => panic!("Unexpected error: {err:?}"), + }; } /// Bind a trait in a let expression @@ -931,17 +878,12 @@ fn test_let_trait() { mem_type_check(let_trait).unwrap(); let err = mem_type_check_v1(let_trait).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::TraitReferenceUnknown(name), - expressions: _, - diagnostic: _, - } => { + match *err.err { + CheckErrors::TraitReferenceUnknown(name) => { assert_eq!(name.as_str(), "t1"); - true } - _ => false, - }); + _ => panic!("Unexpected error: {err:?}"), + }; } /// Bind a trait in transitively in multiple let expressions @@ -962,17 +904,12 @@ fn test_let3_trait() { mem_type_check(let3_trait).unwrap(); let err = mem_type_check_v1(let3_trait).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::TraitReferenceUnknown(name), - expressions: _, - diagnostic: _, - } => { + match *err.err { + CheckErrors::TraitReferenceUnknown(name) => { assert_eq!(name.as_str(), "t3"); - true } - _ => false, - }); + _ => panic!("Unexpected error: {err:?}"), + }; } /// Bind a trait transitively in multiple let expressions with compound types @@ -1022,17 +959,12 @@ fn test_let3_compound_trait_call() { mem_type_check(let3_compound_trait_call).unwrap(); let err = mem_type_check_v1(let3_compound_trait_call).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::TraitReferenceUnknown(name), - expressions: _, - diagnostic: _, - } => { + match *err.err { + CheckErrors::TraitReferenceUnknown(name) => { assert_eq!(name.as_str(), "t4"); - true } - _ => false, - }); + _ => panic!("Unexpected error: {err:?}"), + }; } /// Check for compatibility between traits where the function parameter type @@ -1051,39 +983,27 @@ fn test_trait_args_differ() { (ok true))"; let err = mem_type_check(trait_args_differ).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::IncompatibleTrait(expected, actual), - expressions: _, - diagnostic: _, - } => { + match *err.err { + CheckErrors::IncompatibleTrait(expected, actual) => { assert_eq!(expected.name.as_str(), "trait-2"); assert_eq!(actual.name.as_str(), "trait-1"); - true } - _ => false, - }); + _ => panic!("Unexpected error: {err:?}"), + }; let err = mem_type_check_v1(trait_args_differ).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::TypeError(expected, found), - expressions: _, - diagnostic: _, - } => { - match (expected, found) { - ( - TypeSignature::CallableType(CallableSubtype::Trait(expected_trait)), - TypeSignature::CallableType(CallableSubtype::Trait(found_trait)), - ) => { - assert_eq!(expected_trait.name.as_str(), "trait-2"); - assert_eq!(found_trait.name.as_str(), "trait-1"); - true - } - _ => false, + match *err.err { + CheckErrors::TypeError(expected, found) => match (&*expected, &*found) { + ( + TypeSignature::CallableType(CallableSubtype::Trait(expected_trait)), + TypeSignature::CallableType(CallableSubtype::Trait(found_trait)), + ) => { + assert_eq!(expected_trait.name.as_str(), "trait-2"); + assert_eq!(found_trait.name.as_str(), "trait-1"); } - } - _ => false, - }); + _ => panic!("Unexpected type signatures: {expected:?} {found:?}"), + }, + _ => panic!("Unexpected error: {err:?}"), + }; } /// Pass a trait to a trait parameter with an compatible trait type @@ -1101,39 +1021,27 @@ fn test_trait_arg_counts_differ1() { (ok true))"; let err = mem_type_check(trait_to_compatible_trait).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::IncompatibleTrait(expected, found), - expressions: _, - diagnostic: _, - } => { + match *err.err { + CheckErrors::IncompatibleTrait(expected, found) => { assert_eq!(expected.name.as_str(), "trait-2"); assert_eq!(found.name.as_str(), "trait-1"); - true } - _ => false, - }); + _ => panic!("Unexpected error: {err:?}"), + }; let err = mem_type_check_v1(trait_to_compatible_trait).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::TypeError(expected, found), - expressions: _, - diagnostic: _, - } => { - match (expected, found) { - ( - TypeSignature::CallableType(CallableSubtype::Trait(expected_trait)), - TypeSignature::CallableType(CallableSubtype::Trait(found_trait)), - ) => { - assert_eq!(expected_trait.name.as_str(), "trait-2"); - assert_eq!(found_trait.name.as_str(), "trait-1"); - true - } - _ => false, + match *err.err { + CheckErrors::TypeError(expected, found) => match (&*expected, &*found) { + ( + TypeSignature::CallableType(CallableSubtype::Trait(expected_trait)), + TypeSignature::CallableType(CallableSubtype::Trait(found_trait)), + ) => { + assert_eq!(expected_trait.name.as_str(), "trait-2"); + assert_eq!(found_trait.name.as_str(), "trait-1"); } - } - _ => false, - }); + _ => panic!("Unexpected type signatures: {expected:?} {found:?}"), + }, + _ => panic!("Unexpected error: {err:?}"), + }; } /// Pass a trait to a trait parameter with an compatible trait type @@ -1151,39 +1059,27 @@ fn test_trait_arg_counts_differ2() { (ok true))"; let err = mem_type_check(trait_to_compatible_trait).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::IncompatibleTrait(expected, found), - expressions: _, - diagnostic: _, - } => { + match *err.err { + CheckErrors::IncompatibleTrait(expected, found) => { assert_eq!(expected.name.as_str(), "trait-2"); assert_eq!(found.name.as_str(), "trait-1"); - true } - _ => false, - }); + _ => panic!("Unexpected error: {err:?}"), + }; let err = mem_type_check_v1(trait_to_compatible_trait).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::TypeError(expected, found), - expressions: _, - diagnostic: _, - } => { - match (expected, found) { - ( - TypeSignature::CallableType(CallableSubtype::Trait(expected_trait)), - TypeSignature::CallableType(CallableSubtype::Trait(found_trait)), - ) => { - assert_eq!(expected_trait.name.as_str(), "trait-2"); - assert_eq!(found_trait.name.as_str(), "trait-1"); - true - } - _ => false, + match *err.err { + CheckErrors::TypeError(expected, found) => match (&*expected, &*found) { + ( + TypeSignature::CallableType(CallableSubtype::Trait(expected_trait)), + TypeSignature::CallableType(CallableSubtype::Trait(found_trait)), + ) => { + assert_eq!(expected_trait.name.as_str(), "trait-2"); + assert_eq!(found_trait.name.as_str(), "trait-1"); } - } - _ => false, - }); + _ => panic!("Unexpected type signatures: {expected:?} {found:?}"), + }, + _ => panic!("Unexpected error: {err:?}"), + }; } /// Check for compatibility between traits where the response types differ @@ -1201,39 +1097,27 @@ fn test_trait_ret_ty_differ() { (contract-call? contract echo u1))"; let err = mem_type_check(trait_ret_ty_differ).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::IncompatibleTrait(expected, actual), - expressions: _, - diagnostic: _, - } => { + match *err.err { + CheckErrors::IncompatibleTrait(expected, actual) => { assert_eq!(expected.name.as_str(), "trait-2"); assert_eq!(actual.name.as_str(), "trait-1"); - true } - _ => false, - }); + _ => panic!("Unexpected error: {err:?}"), + }; let err = mem_type_check_v1(trait_ret_ty_differ).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::TypeError(expected, found), - expressions: _, - diagnostic: _, - } => { - match (expected, found) { - ( - TypeSignature::CallableType(CallableSubtype::Trait(expected_trait)), - TypeSignature::CallableType(CallableSubtype::Trait(found_trait)), - ) => { - assert_eq!(expected_trait.name.as_str(), "trait-2"); - assert_eq!(found_trait.name.as_str(), "trait-1"); - true - } - _ => false, + match *err.err { + CheckErrors::TypeError(expected, found) => match (&*expected, &*found) { + ( + TypeSignature::CallableType(CallableSubtype::Trait(expected_trait)), + TypeSignature::CallableType(CallableSubtype::Trait(found_trait)), + ) => { + assert_eq!(expected_trait.name.as_str(), "trait-2"); + assert_eq!(found_trait.name.as_str(), "trait-1"); } - } - _ => false, - }); + _ => panic!("Unexpected type signatures: {expected:?} {found:?}"), + }, + _ => panic!("Unexpected error: {err:?}"), + }; } /// Check for compatibility of traits where a function parameter has a @@ -1259,26 +1143,19 @@ fn test_trait_with_compatible_trait_arg() { mem_type_check(trait_with_compatible_trait_arg).unwrap(); let err = mem_type_check_v1(trait_with_compatible_trait_arg).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::TypeError(expected, found), - expressions: _, - diagnostic: _, - } => { - match (expected, found) { - ( - TypeSignature::CallableType(CallableSubtype::Trait(expected_trait)), - TypeSignature::CallableType(CallableSubtype::Trait(found_trait)), - ) => { - assert_eq!(expected_trait.name.as_str(), "trait-b"); - assert_eq!(found_trait.name.as_str(), "trait-a"); - true - } - _ => false, + match *err.err { + CheckErrors::TypeError(expected, found) => match (&*expected, &*found) { + ( + TypeSignature::CallableType(CallableSubtype::Trait(expected_trait)), + TypeSignature::CallableType(CallableSubtype::Trait(found_trait)), + ) => { + assert_eq!(expected_trait.name.as_str(), "trait-b"); + assert_eq!(found_trait.name.as_str(), "trait-a"); } - } - _ => false, - }); + _ => panic!("Unexpected type signatures: {expected:?} {found:?}"), + }, + _ => panic!("Unexpected error: {err:?}"), + }; } /// Check for compatibility of traits where a function parameter has an @@ -1303,39 +1180,27 @@ fn test_trait_with_bad_trait_arg() { (contract-call? contract echo callee))"; let err = mem_type_check(trait_with_bad_trait_arg).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::IncompatibleTrait(expected, actual), - expressions: _, - diagnostic: _, - } => { + match *err.err { + CheckErrors::IncompatibleTrait(expected, actual) => { assert_eq!(expected.name.as_str(), "trait-b"); assert_eq!(actual.name.as_str(), "trait-a"); - true } - _ => false, - }); + _ => panic!("Unexpected error: {err:?}"), + }; let err = mem_type_check_v1(trait_with_bad_trait_arg).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::TypeError(expected, found), - expressions: _, - diagnostic: _, - } => { - match (expected, found) { - ( - TypeSignature::CallableType(CallableSubtype::Trait(expected_trait)), - TypeSignature::CallableType(CallableSubtype::Trait(found_trait)), - ) => { - assert_eq!(expected_trait.name.as_str(), "trait-b"); - assert_eq!(found_trait.name.as_str(), "trait-a"); - true - } - _ => false, + match *err.err { + CheckErrors::TypeError(expected, found) => match (&*expected, &*found) { + ( + TypeSignature::CallableType(CallableSubtype::Trait(expected_trait)), + TypeSignature::CallableType(CallableSubtype::Trait(found_trait)), + ) => { + assert_eq!(expected_trait.name.as_str(), "trait-b"); + assert_eq!(found_trait.name.as_str(), "trait-a"); } - } - _ => false, - }); + _ => panic!("Unexpected type signatures: {expected:?} {found:?}"), + }, + _ => panic!("Unexpected error: {err:?}"), + }; } /// Check for compatibility of traits where a function parameter from one trait @@ -1361,39 +1226,29 @@ fn test_trait_with_superset_trait_arg() { (contract-call? contract echo callee))"; let err = mem_type_check(trait_with_superset_trait_arg).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::IncompatibleTrait(expected, actual), - expressions: _, - diagnostic: _, - } => { + match *err.err { + CheckErrors::IncompatibleTrait(expected, actual) => { assert_eq!(expected.name.as_str(), "trait-b"); assert_eq!(actual.name.as_str(), "trait-a"); - true } - _ => false, - }); + _ => panic!("Unexpected error: {err:?}"), + }; + let err = mem_type_check_v1(trait_with_superset_trait_arg).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::TypeError(expected, found), - expressions: _, - diagnostic: _, - } => { - match (expected, found) { - ( - TypeSignature::CallableType(CallableSubtype::Trait(expected_trait)), - TypeSignature::CallableType(CallableSubtype::Trait(found_trait)), - ) => { - assert_eq!(expected_trait.name.as_str(), "trait-b"); - assert_eq!(found_trait.name.as_str(), "trait-a"); - true - } - _ => false, + + match *err.err { + CheckErrors::TypeError(expected, found) => match (&*expected, &*found) { + ( + TypeSignature::CallableType(CallableSubtype::Trait(expected_trait)), + TypeSignature::CallableType(CallableSubtype::Trait(found_trait)), + ) => { + assert_eq!(expected_trait.name.as_str(), "trait-b"); + assert_eq!(found_trait.name.as_str(), "trait-a"); } - } - _ => false, - }); + _ => panic!("Unexpected TypeSignatures: {expected:?} {found:?}"), + }, + _ => panic!("Unexpected error: {err:?}"), + } } /// Check for compatibility of traits where a function parameter from one trait @@ -1420,26 +1275,19 @@ fn test_trait_with_subset_trait_arg() { mem_type_check(trait_with_subset_trait_arg).unwrap(); let err = mem_type_check_v1(trait_with_subset_trait_arg).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::TypeError(expected, found), - expressions: _, - diagnostic: _, - } => { - match (expected, found) { - ( - TypeSignature::CallableType(CallableSubtype::Trait(expected_trait)), - TypeSignature::CallableType(CallableSubtype::Trait(found_trait)), - ) => { - assert_eq!(expected_trait.name.as_str(), "trait-a"); - assert_eq!(found_trait.name.as_str(), "trait-b"); - true - } - _ => false, + match *err.err { + CheckErrors::TypeError(expected, found) => match (&*expected, &*found) { + ( + TypeSignature::CallableType(CallableSubtype::Trait(expected_trait)), + TypeSignature::CallableType(CallableSubtype::Trait(found_trait)), + ) => { + assert_eq!(expected_trait.name.as_str(), "trait-a"); + assert_eq!(found_trait.name.as_str(), "trait-b"); } - } - _ => false, - }); + _ => panic!("Unexpected type signatures: {expected:?} {found:?}"), + }, + _ => panic!("Unexpected error: {err:?}"), + }; } /// Define a trait with a duplicated method name @@ -1451,17 +1299,12 @@ fn test_trait_with_duplicate_method() { ))"; let err = mem_type_check(trait_with_duplicate_method).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::DefineTraitDuplicateMethod(method_name), - expressions: _, - diagnostic: _, - } => { + match *err.err { + CheckErrors::DefineTraitDuplicateMethod(method_name) => { assert_eq!(method_name.as_str(), "foo"); - true } - _ => false, - }); + _ => panic!("Unexpected error: {err:?}"), + }; mem_type_check_v1(trait_with_duplicate_method).unwrap(); } @@ -1485,39 +1328,27 @@ fn test_trait_to_subtrait_and_back() { true)"; let err = mem_type_check(trait_to_subtrait_and_back).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::IncompatibleTrait(expected, actual), - expressions: _, - diagnostic: _, - } => { + match *err.err { + CheckErrors::IncompatibleTrait(expected, actual) => { assert_eq!(expected.name.as_str(), "trait-2"); assert_eq!(actual.name.as_str(), "trait-1"); - true } - _ => false, - }); + _ => panic!("Unexpected error: {err:?}"), + }; let err = mem_type_check_v1(trait_to_subtrait_and_back).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::TypeError(expected, found), - expressions: _, - diagnostic: _, - } => { - match (expected, found) { - ( - TypeSignature::CallableType(CallableSubtype::Trait(expected_trait)), - TypeSignature::CallableType(CallableSubtype::Trait(found_trait)), - ) => { - assert_eq!(expected_trait.name.as_str(), "trait-2"); - assert_eq!(found_trait.name.as_str(), "trait-1"); - true - } - _ => false, + match *err.err { + CheckErrors::TypeError(expected, found) => match (&*expected, &*found) { + ( + TypeSignature::CallableType(CallableSubtype::Trait(expected_trait)), + TypeSignature::CallableType(CallableSubtype::Trait(found_trait)), + ) => { + assert_eq!(expected_trait.name.as_str(), "trait-2"); + assert_eq!(found_trait.name.as_str(), "trait-1"); } - } - _ => false, - }); + _ => panic!("Unexpected type signatures: {expected:?} {found:?}"), + }, + _ => panic!("Unexpected error: {err:?}"), + }; } /// Use `map` on a list of traits @@ -1552,47 +1383,33 @@ fn test_if_branches_with_incompatible_trait_types() { ) )"; let err = mem_type_check(if_branches_with_incompatible_trait_types).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::IfArmsMustMatch(type1, type2), - expressions: _, - diagnostic: _, - } => { - match (type1, type2) { - ( - TypeSignature::CallableType(CallableSubtype::Trait(trait1)), - TypeSignature::CallableType(CallableSubtype::Trait(trait2)), - ) => { - assert_eq!(trait1.name.as_str(), "trait-1"); - assert_eq!(trait2.name.as_str(), "trait-2"); - true - } - _ => false, + match *err.err { + CheckErrors::IfArmsMustMatch(type1, type2) => match (&*type1, &*type2) { + ( + TypeSignature::CallableType(CallableSubtype::Trait(trait1)), + TypeSignature::CallableType(CallableSubtype::Trait(trait2)), + ) => { + assert_eq!(trait1.name.as_str(), "trait-1"); + assert_eq!(trait2.name.as_str(), "trait-2"); } - } - _ => false, - }); + _ => panic!("Unexpected type signatures: {type1:?} {type2:?}"), + }, + _ => panic!("Unexpected error: {err:?}"), + }; let err = mem_type_check_v1(if_branches_with_incompatible_trait_types).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::IfArmsMustMatch(type1, type2), - expressions: _, - diagnostic: _, - } => { - match (type1, type2) { - ( - TypeSignature::CallableType(CallableSubtype::Trait(trait1)), - TypeSignature::CallableType(CallableSubtype::Trait(trait2)), - ) => { - assert_eq!(trait1.name.as_str(), "trait-1"); - assert_eq!(trait2.name.as_str(), "trait-2"); - true - } - _ => false, + match *err.err { + CheckErrors::IfArmsMustMatch(type1, type2) => match (&*type1, &*type2) { + ( + TypeSignature::CallableType(CallableSubtype::Trait(trait1)), + TypeSignature::CallableType(CallableSubtype::Trait(trait2)), + ) => { + assert_eq!(trait1.name.as_str(), "trait-1"); + assert_eq!(trait2.name.as_str(), "trait-2"); } - } - _ => false, - }); + _ => panic!("Unexpected type signatures: {type1:?} {type2:?}"), + }, + _ => panic!("Unexpected error: {err:?}"), + }; } /// If branches with compatible trait types @@ -1612,47 +1429,33 @@ fn test_if_branches_with_compatible_trait_types() { )"; let err = mem_type_check(if_branches_with_compatible_trait_types).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::IfArmsMustMatch(type1, type2), - expressions: _, - diagnostic: _, - } => { - match (type1, type2) { - ( - TypeSignature::CallableType(CallableSubtype::Trait(trait1)), - TypeSignature::CallableType(CallableSubtype::Trait(trait2)), - ) => { - assert_eq!(trait1.name.as_str(), "trait-1"); - assert_eq!(trait2.name.as_str(), "trait-2"); - true - } - _ => false, + match *err.err { + CheckErrors::IfArmsMustMatch(type1, type2) => match (&*type1, &*type2) { + ( + TypeSignature::CallableType(CallableSubtype::Trait(trait1)), + TypeSignature::CallableType(CallableSubtype::Trait(trait2)), + ) => { + assert_eq!(trait1.name.as_str(), "trait-1"); + assert_eq!(trait2.name.as_str(), "trait-2"); } - } - _ => false, - }); + _ => panic!("Unexpected type signatures: {type1:?} {type2:?}"), + }, + _ => panic!("Unexpected error: {err:?}"), + }; let err = mem_type_check_v1(if_branches_with_compatible_trait_types).unwrap_err(); - assert!(match err { - CheckError { - err: CheckErrors::IfArmsMustMatch(type1, type2), - expressions: _, - diagnostic: _, - } => { - match (type1, type2) { - ( - TypeSignature::CallableType(CallableSubtype::Trait(trait1)), - TypeSignature::CallableType(CallableSubtype::Trait(trait2)), - ) => { - assert_eq!(trait1.name.as_str(), "trait-1"); - assert_eq!(trait2.name.as_str(), "trait-2"); - true - } - _ => false, + match *err.err { + CheckErrors::IfArmsMustMatch(type1, type2) => match (&*type1, &*type2) { + ( + TypeSignature::CallableType(CallableSubtype::Trait(trait1)), + TypeSignature::CallableType(CallableSubtype::Trait(trait2)), + ) => { + assert_eq!(trait1.name.as_str(), "trait-1"); + assert_eq!(trait2.name.as_str(), "trait-2"); } - } - _ => false, - }); + _ => panic!("Unexpected type signatures: {type1:?} {type2:?}"), + }, + _ => panic!("Unexpected error: {err:?}"), + }; } /// Based on issue #3215 from sskeirik @@ -1679,7 +1482,7 @@ fn test_traits_multi_contract(#[case] version: ClarityVersion) { let mut marf = MemoryBackingStore::new(); let mut db = marf.as_analysis_db(); - match db.execute(|db| { + let result = db.execute(|db| { type_check_version( &trait_contract_id, &mut trait_contract, @@ -1696,17 +1499,17 @@ fn test_traits_multi_contract(#[case] version: ClarityVersion) { StacksEpochId::Epoch21, version, ) - }) { - Err(CheckError { - err: CheckErrors::TraitMethodUnknown(trait_name, function), - expressions: _, - diagnostic: _, - }) if version < ClarityVersion::Clarity2 => { - assert_eq!(trait_name.as_str(), "a"); - assert_eq!(function.as_str(), "do-it"); - } + }); + match result { Ok(_) if version >= ClarityVersion::Clarity2 => (), - res => panic!("{res:?}"), + Err(CheckError { err, .. }) if version < ClarityVersion::Clarity2 => match *err { + CheckErrors::TraitMethodUnknown(trait_name, function) => { + assert_eq!(trait_name.as_str(), "a"); + assert_eq!(function.as_str(), "do-it"); + } + _ => panic!("Unexpected error: {err:?}"), + }, + _ => panic!("Unexpected result: {result:?}"), } } diff --git a/clarity/src/vm/analysis/type_checker/v2_1/tests/mod.rs b/clarity/src/vm/analysis/type_checker/v2_1/tests/mod.rs index c3c54b56d61..9c1bc3f008c 100644 --- a/clarity/src/vm/analysis/type_checker/v2_1/tests/mod.rs +++ b/clarity/src/vm/analysis/type_checker/v2_1/tests/mod.rs @@ -99,8 +99,8 @@ fn test_from_consensus_buff() { ( "(from-consensus-buff? int u6)", CheckErrors::TypeError( - TypeSignature::max_buffer().unwrap(), - TypeSignature::UIntType, + Box::new(TypeSignature::max_buffer().unwrap()), + Box::new(TypeSignature::UIntType), ), ), ( @@ -125,7 +125,7 @@ fn test_from_consensus_buff() { } for (bad_test, expected) in bad.iter() { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -221,7 +221,7 @@ fn test_to_consensus_buff() { } for (bad_test, expected) in bad.iter() { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -261,8 +261,8 @@ fn test_get_block_info() { ]; let bad_expected = [ CheckErrors::NoSuchBlockInfoProperty("none".to_string()), - CheckErrors::TypeError(UIntType, BoolType), - CheckErrors::TypeError(UIntType, IntType), + CheckErrors::TypeError(Box::new(UIntType), Box::new(BoolType)), + CheckErrors::TypeError(Box::new(UIntType), Box::new(IntType)), CheckErrors::RequiresAtLeastArguments(2, 1), ]; @@ -287,8 +287,8 @@ fn test_get_block_info() { for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { assert_eq!( - expected, - &type_check_helper_version(bad_test, ClarityVersion::Clarity2) + *expected, + *type_check_helper_version(bad_test, ClarityVersion::Clarity2) .unwrap_err() .err ); @@ -296,7 +296,7 @@ fn test_get_block_info() { for good_test in good_v210.iter() { if let CheckErrors::NoSuchBlockInfoProperty(_) = - type_check_helper_v1(good_test).unwrap_err().err + *type_check_helper_v1(good_test).unwrap_err().err { } else { panic!("Failed to get a typecheck error when using a v2 property in a v1 context"); @@ -320,10 +320,10 @@ fn test_get_burn_block_info() { CheckErrors::IncorrectArgumentCount(2, 0), CheckErrors::IncorrectArgumentCount(2, 1), CheckErrors::TypeError( - UIntType, - SequenceType(StringType(ASCII( + Box::new(UIntType), + Box::new(SequenceType(StringType(ASCII( BufferLength::try_from(1u32).expect("BufferLength::try_from failed"), - ))), + )))), ), ]; @@ -335,7 +335,7 @@ fn test_get_burn_block_info() { } for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -367,7 +367,7 @@ fn test_define_trait(#[case] version: ClarityVersion, #[case] epoch: StacksEpoch ]; for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } let bad = ["(define-trait trait-1)", "(define-trait)"]; @@ -379,7 +379,7 @@ fn test_define_trait(#[case] version: ClarityVersion, #[case] epoch: StacksEpoch let contract_identifier = QualifiedContractIdentifier::transient(); for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { let res = build_ast(&contract_identifier, bad_test, &mut (), version, epoch).unwrap_err(); - assert_eq!(expected, &res.err); + assert_eq!(*expected, *res.err); } } @@ -401,7 +401,7 @@ fn test_use_trait(#[case] version: ClarityVersion, #[case] epoch: StacksEpochId) let contract_identifier = QualifiedContractIdentifier::transient(); for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { let res = build_ast(&contract_identifier, bad_test, &mut (), version, epoch).unwrap_err(); - assert_eq!(expected, &res.err); + assert_eq!(*expected, *res.err); } } @@ -416,7 +416,7 @@ fn test_impl_trait(#[case] version: ClarityVersion, #[case] epoch: StacksEpochId let contract_identifier = QualifiedContractIdentifier::transient(); for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { let res = build_ast(&contract_identifier, bad_test, &mut (), version, epoch).unwrap_err(); - assert_eq!(expected, &res.err); + assert_eq!(*expected, *res.err); } } @@ -459,30 +459,40 @@ fn test_stx_ops() { ]; let bad_expected = [ CheckErrors::TypeError( - PrincipalType, - SequenceType(BufferType(BufferLength::try_from(2_u32).unwrap())), + Box::new(PrincipalType), + Box::new(SequenceType(BufferType( + BufferLength::try_from(2_u32).unwrap(), + ))), ), - CheckErrors::TypeError(UIntType, IntType), + CheckErrors::TypeError(Box::new(UIntType), Box::new(IntType)), CheckErrors::IncorrectArgumentCount(3, 5), - CheckErrors::TypeError(PrincipalType, UIntType), - CheckErrors::TypeError(PrincipalType, BoolType), - CheckErrors::TypeError(PrincipalType, OptionalType(Box::from(PrincipalType))), + CheckErrors::TypeError(Box::new(PrincipalType), Box::new(UIntType)), + CheckErrors::TypeError(Box::new(PrincipalType), Box::new(BoolType)), + CheckErrors::TypeError( + Box::new(PrincipalType), + Box::new(OptionalType(Box::from(PrincipalType))), + ), CheckErrors::IncorrectArgumentCount(3, 4), CheckErrors::TypeError( - PrincipalType, - SequenceType(BufferType(BufferLength::try_from(2_u32).unwrap())), + Box::new(PrincipalType), + Box::new(SequenceType(BufferType( + BufferLength::try_from(2_u32).unwrap(), + ))), ), - CheckErrors::TypeError(UIntType, IntType), + CheckErrors::TypeError(Box::new(UIntType), Box::new(IntType)), CheckErrors::IncorrectArgumentCount(4, 5), - CheckErrors::TypeError(PrincipalType, UIntType), - CheckErrors::TypeError(PrincipalType, BoolType), - CheckErrors::TypeError(PrincipalType, OptionalType(Box::from(PrincipalType))), + CheckErrors::TypeError(Box::new(PrincipalType), Box::new(UIntType)), + CheckErrors::TypeError(Box::new(PrincipalType), Box::new(BoolType)), + CheckErrors::TypeError( + Box::new(PrincipalType), + Box::new(OptionalType(Box::from(PrincipalType))), + ), CheckErrors::IncorrectArgumentCount(4, 3), CheckErrors::IncorrectArgumentCount(2, 1), - CheckErrors::TypeError(UIntType, IntType), - CheckErrors::TypeError(PrincipalType, BoolType), + CheckErrors::TypeError(Box::new(UIntType), Box::new(IntType)), + CheckErrors::TypeError(Box::new(PrincipalType), Box::new(BoolType)), CheckErrors::IncorrectArgumentCount(2, 3), - CheckErrors::TypeError(PrincipalType, BoolType), + CheckErrors::TypeError(Box::new(PrincipalType), Box::new(BoolType)), CheckErrors::IncorrectArgumentCount(1, 2), ]; @@ -494,7 +504,7 @@ fn test_stx_ops() { } for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -513,8 +523,8 @@ fn test_tx_sponsor() { let bad = ["(stx-transfer? u10 tx-sponsor? 'SM2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQVX8X0G)"]; let bad_expected = [CheckErrors::TypeError( - PrincipalType, - OptionalType(Box::from(PrincipalType)), + Box::new(PrincipalType), + Box::new(OptionalType(Box::from(PrincipalType))), )]; for (good_test, expected) in good.iter().zip(expected.iter()) { @@ -525,7 +535,7 @@ fn test_tx_sponsor() { } for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -580,11 +590,11 @@ fn test_destructuring_opts(#[case] version: ClarityVersion, #[case] epoch: Stack let bad = [ ( "(unwrap-err! (some 2) 2)", - CheckErrors::ExpectedResponseType(TypeSignature::from_string( + CheckErrors::ExpectedResponseType(Box::new(TypeSignature::from_string( "(optional int)", version, epoch, - )), + ))), ), ( "(unwrap! (err 3) 2)", @@ -621,11 +631,17 @@ fn test_destructuring_opts(#[case] version: ClarityVersion, #[case] epoch: Stack ( "(define-private (foo) (if (> 1 0) (ok 1) (err u8))) (match (foo) ok-val (+ 1 ok-val) err-val (/ err-val u0))", - CheckErrors::MatchArmsMustMatch(TypeSignature::IntType, TypeSignature::UIntType), + CheckErrors::MatchArmsMustMatch( + Box::new(TypeSignature::IntType), + Box::new(TypeSignature::UIntType), + ), ), ( "(match (some 1) inner-value (+ 1 inner-value) (> 1 28))", - CheckErrors::MatchArmsMustMatch(TypeSignature::IntType, TypeSignature::BoolType), + CheckErrors::MatchArmsMustMatch( + Box::new(TypeSignature::IntType), + Box::new(TypeSignature::BoolType), + ), ), ( "(match (some 1) inner-value (+ 1 inner-value))", @@ -652,11 +668,11 @@ fn test_destructuring_opts(#[case] version: ClarityVersion, #[case] epoch: Stack ("(match)", CheckErrors::RequiresAtLeastArguments(1, 0)), ( "(match 1 ok-val (/ ok-val 0) err-val (+ err-val 7))", - CheckErrors::BadMatchInput(TypeSignature::from_string("int", version, epoch)), + CheckErrors::BadMatchInput(Box::new(TypeSignature::from_string("int", version, epoch))), ), ( "(default-to 3 5)", - CheckErrors::ExpectedOptionalType(TypeSignature::IntType), + CheckErrors::ExpectedOptionalType(Box::new(TypeSignature::IntType)), ), ( "(define-private (foo (x int)) @@ -672,10 +688,14 @@ fn test_destructuring_opts(#[case] version: ClarityVersion, #[case] epoch: Stack (err u3) (ok (+ u2 (try! (t1 x))))))", CheckErrors::ReturnTypesMustMatch( - TypeSignature::new_response(TypeSignature::NoType, TypeSignature::BoolType) - .unwrap(), - TypeSignature::new_response(TypeSignature::UIntType, TypeSignature::UIntType) - .unwrap(), + Box::new( + TypeSignature::new_response(TypeSignature::NoType, TypeSignature::BoolType) + .unwrap(), + ), + Box::new( + TypeSignature::new_response(TypeSignature::UIntType, TypeSignature::UIntType) + .unwrap(), + ), ), ), ( @@ -683,9 +703,11 @@ fn test_destructuring_opts(#[case] version: ClarityVersion, #[case] epoch: Stack (define-private (t2 (x uint)) (> u2 (try! (t1 x))))", CheckErrors::ReturnTypesMustMatch( - TypeSignature::new_response(TypeSignature::NoType, TypeSignature::BoolType) - .unwrap(), - TypeSignature::BoolType, + Box::new( + TypeSignature::new_response(TypeSignature::NoType, TypeSignature::BoolType) + .unwrap(), + ), + Box::new(TypeSignature::BoolType), ), ), ( @@ -699,7 +721,7 @@ fn test_destructuring_opts(#[case] version: ClarityVersion, #[case] epoch: Stack ), ( "(try! 3)", - CheckErrors::ExpectedOptionalOrResponseType(TypeSignature::IntType), + CheckErrors::ExpectedOptionalOrResponseType(Box::new(TypeSignature::IntType)), ), ("(try! (ok 3) 4)", CheckErrors::IncorrectArgumentCount(1, 2)), ]; @@ -712,7 +734,7 @@ fn test_destructuring_opts(#[case] version: ClarityVersion, #[case] epoch: Stack } for (bad_test, expected) in bad.iter() { - assert_eq!(expected, &mem_type_check(bad_test).unwrap_err().err); + assert_eq!(*expected, *mem_type_check(bad_test).unwrap_err().err); } } @@ -723,7 +745,7 @@ fn test_at_block() { let bad = [ ( "(at-block (sha512 u0) u1)", - CheckErrors::TypeError(BUFF_32.clone(), BUFF_64.clone()), + CheckErrors::TypeError(Box::new(BUFF_32.clone()), Box::new(BUFF_64.clone())), ), ( "(at-block (sha256 u0) u1 u2)", @@ -739,7 +761,7 @@ fn test_at_block() { } for (bad_test, expected) in bad.iter() { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -753,7 +775,7 @@ fn test_trait_reference_unknown(#[case] version: ClarityVersion, #[case] epoch: let contract_identifier = QualifiedContractIdentifier::transient(); for (bad_test, expected) in bad.iter() { let res = build_ast(&contract_identifier, bad_test, &mut (), version, epoch).unwrap_err(); - assert_eq!(expected, &res.err); + assert_eq!(*expected, *res.err); } } @@ -765,7 +787,7 @@ fn test_unexpected_use_of_field_or_trait_reference() { )]; for (bad_test, expected) in bad.iter() { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -809,24 +831,26 @@ fn test_bitwise_bad_checks() { ]; let bad_expected = [ CheckErrors::IncorrectArgumentCount(2, 1), - CheckErrors::TypeError(IntType, UIntType), - CheckErrors::TypeError(UIntType, IntType), + CheckErrors::TypeError(Box::new(IntType), Box::new(UIntType)), + CheckErrors::TypeError(Box::new(UIntType), Box::new(IntType)), CheckErrors::UnionTypeError( vec![IntType, UIntType], - SequenceType(StringType(ASCII(BufferLength::try_from(5u32).unwrap()))), + Box::new(SequenceType(StringType(ASCII( + BufferLength::try_from(5u32).unwrap(), + )))), ), CheckErrors::IncorrectArgumentCount(1, 2), - CheckErrors::TypeError(IntType, UIntType), + CheckErrors::TypeError(Box::new(IntType), Box::new(UIntType)), CheckErrors::IncorrectArgumentCount(2, 1), CheckErrors::IncorrectArgumentCount(2, 1), - CheckErrors::UnionTypeError(vec![IntType, UIntType], BoolType), - CheckErrors::TypeError(UIntType, IntType), - CheckErrors::TypeError(UIntType, IntType), - CheckErrors::TypeError(IntType, UIntType), + CheckErrors::UnionTypeError(vec![IntType, UIntType], Box::new(BoolType)), + CheckErrors::TypeError(Box::new(UIntType), Box::new(IntType)), + CheckErrors::TypeError(Box::new(UIntType), Box::new(IntType)), + CheckErrors::TypeError(Box::new(IntType), Box::new(UIntType)), ]; for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -847,12 +871,12 @@ fn test_simple_arithmetic_checks() { "(and (or true false) (+ 1 2 3))", ]; let bad_expected = [ - CheckErrors::TypeError(IntType, BoolType), + CheckErrors::TypeError(Box::new(IntType), Box::new(BoolType)), CheckErrors::RequiresAtLeastArguments(1, 0), CheckErrors::IncorrectArgumentCount(2, 1), CheckErrors::UndefinedVariable("x".to_string()), - CheckErrors::TypeError(IntType, BoolType), - CheckErrors::TypeError(BoolType, IntType), + CheckErrors::TypeError(Box::new(IntType), Box::new(BoolType)), + CheckErrors::TypeError(Box::new(BoolType), Box::new(IntType)), ]; for (good_test, expected) in good.iter().zip(expected.iter()) { @@ -863,7 +887,7 @@ fn test_simple_arithmetic_checks() { } for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -912,14 +936,14 @@ fn test_simple_hash_checks() { for bad_test in bad_types.iter() { assert!(matches!( - type_check_helper(bad_test).unwrap_err().err, + *type_check_helper(bad_test).unwrap_err().err, CheckErrors::UnionTypeError(_, _) )); } for bad_test in invalid_args.iter() { assert!(matches!( - type_check_helper(bad_test).unwrap_err().err, + *type_check_helper(bad_test).unwrap_err().err, CheckErrors::IncorrectArgumentCount(_, _) )); } @@ -943,10 +967,10 @@ fn test_simple_ifs() { ]; let bad_expected = [ - CheckErrors::IfArmsMustMatch(BoolType, IntType), - CheckErrors::IfArmsMustMatch(ascii_type(1), BoolType), + CheckErrors::IfArmsMustMatch(Box::new(BoolType), Box::new(IntType)), + CheckErrors::IfArmsMustMatch(Box::new(ascii_type(1)), Box::new(BoolType)), CheckErrors::IncorrectArgumentCount(3, 0), - CheckErrors::TypeError(BoolType, IntType), + CheckErrors::TypeError(Box::new(BoolType), Box::new(IntType)), ]; for (good_test, expected) in good.iter().zip(expected.iter()) { @@ -957,7 +981,7 @@ fn test_simple_ifs() { } for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -981,7 +1005,10 @@ fn test_simple_lets() { let bad_expected = [ CheckErrors::BadSyntaxBinding, CheckErrors::BadSyntaxBinding, - CheckErrors::TypeError(TypeSignature::IntType, TypeSignature::UIntType), + CheckErrors::TypeError( + Box::new(TypeSignature::IntType), + Box::new(TypeSignature::UIntType), + ), ]; for (good_test, expected) in good.iter().zip(expected.iter()) { @@ -992,7 +1019,7 @@ fn test_simple_lets() { } for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -1051,37 +1078,43 @@ fn test_index_of() { ]; let bad_expected = [ - CheckErrors::ExpectedSequence(TypeSignature::IntType), - CheckErrors::TypeError(TypeSignature::IntType, TypeSignature::UIntType), + CheckErrors::ExpectedSequence(Box::new(TypeSignature::IntType)), CheckErrors::TypeError( - TypeSignature::min_buffer().unwrap(), - TypeSignature::min_string_ascii().unwrap(), + Box::new(TypeSignature::IntType), + Box::new(TypeSignature::UIntType), ), CheckErrors::TypeError( - TypeSignature::min_string_utf8().unwrap(), - TypeSignature::min_string_ascii().unwrap(), + Box::new(TypeSignature::min_buffer().unwrap()), + Box::new(TypeSignature::min_string_ascii().unwrap()), ), CheckErrors::TypeError( - TypeSignature::min_string_ascii().unwrap(), - TypeSignature::min_string_utf8().unwrap(), + Box::new(TypeSignature::min_string_utf8().unwrap()), + Box::new(TypeSignature::min_string_ascii().unwrap()), ), CheckErrors::TypeError( - TypeSignature::list_of(TypeSignature::IntType, 1).unwrap(), - TypeSignature::list_of(TypeSignature::IntType, 2).unwrap(), + Box::new(TypeSignature::min_string_ascii().unwrap()), + Box::new(TypeSignature::min_string_utf8().unwrap()), ), - CheckErrors::ExpectedSequence(TypeSignature::IntType), - CheckErrors::TypeError(TypeSignature::IntType, TypeSignature::UIntType), CheckErrors::TypeError( - TypeSignature::min_buffer().unwrap(), - TypeSignature::min_string_ascii().unwrap(), + Box::new(TypeSignature::list_of(TypeSignature::IntType, 1).unwrap()), + Box::new(TypeSignature::list_of(TypeSignature::IntType, 2).unwrap()), ), + CheckErrors::ExpectedSequence(Box::new(TypeSignature::IntType)), CheckErrors::TypeError( - TypeSignature::min_string_utf8().unwrap(), - TypeSignature::min_string_ascii().unwrap(), + Box::new(TypeSignature::IntType), + Box::new(TypeSignature::UIntType), ), CheckErrors::TypeError( - TypeSignature::min_string_ascii().unwrap(), - TypeSignature::min_string_utf8().unwrap(), + Box::new(TypeSignature::min_buffer().unwrap()), + Box::new(TypeSignature::min_string_ascii().unwrap()), + ), + CheckErrors::TypeError( + Box::new(TypeSignature::min_string_utf8().unwrap()), + Box::new(TypeSignature::min_string_ascii().unwrap()), + ), + CheckErrors::TypeError( + Box::new(TypeSignature::min_string_ascii().unwrap()), + Box::new(TypeSignature::min_string_utf8().unwrap()), ), CheckErrors::CouldNotDetermineType, CheckErrors::CouldNotDetermineType, @@ -1089,7 +1122,7 @@ fn test_index_of() { ]; for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -1129,10 +1162,16 @@ fn test_element_at() { ]; let bad_expected = [ - CheckErrors::TypeError(TypeSignature::UIntType, TypeSignature::IntType), - CheckErrors::ExpectedSequence(TypeSignature::IntType), - CheckErrors::TypeError(TypeSignature::UIntType, TypeSignature::IntType), - CheckErrors::ExpectedSequence(TypeSignature::IntType), + CheckErrors::TypeError( + Box::new(TypeSignature::UIntType), + Box::new(TypeSignature::IntType), + ), + CheckErrors::ExpectedSequence(Box::new(TypeSignature::IntType)), + CheckErrors::TypeError( + Box::new(TypeSignature::UIntType), + Box::new(TypeSignature::IntType), + ), + CheckErrors::ExpectedSequence(Box::new(TypeSignature::IntType)), ]; for (good_test, expected) in good.iter().zip(expected.iter()) { @@ -1143,7 +1182,7 @@ fn test_element_at() { } for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -1164,11 +1203,18 @@ fn test_eqs(#[case] version: ClarityVersion, #[case] epoch: StacksEpochId) { ]; let bad_expected = [ - CheckErrors::TypeError(BoolType, IntType), - CheckErrors::TypeError(TypeSignature::list_of(IntType, 1).unwrap(), IntType), + CheckErrors::TypeError(Box::new(BoolType), Box::new(IntType)), CheckErrors::TypeError( - TypeSignature::from_string("(optional bool)", version, epoch), - TypeSignature::from_string("(optional int)", version, epoch), + Box::new(TypeSignature::list_of(IntType, 1).unwrap()), + Box::new(IntType), + ), + CheckErrors::TypeError( + Box::new(TypeSignature::from_string( + "(optional bool)", + version, + epoch, + )), + Box::new(TypeSignature::from_string("(optional int)", version, epoch)), ), ]; @@ -1180,7 +1226,7 @@ fn test_eqs(#[case] version: ClarityVersion, #[case] epoch: StacksEpochId) { } for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -1201,7 +1247,7 @@ fn test_asserts() { let bad_expected = [ CheckErrors::IncorrectArgumentCount(2, 1), - CheckErrors::TypeError(BoolType, IntType), + CheckErrors::TypeError(Box::new(BoolType), Box::new(IntType)), CheckErrors::IncorrectArgumentCount(2, 3), ]; @@ -1213,7 +1259,7 @@ fn test_asserts() { } for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -1266,23 +1312,23 @@ fn test_lists() { "(map + (list 1 2 3 4 5) (list true true true true true))", ]; let bad_expected = [ - CheckErrors::TypeError(BoolType, IntType), + CheckErrors::TypeError(Box::new(BoolType), Box::new(IntType)), CheckErrors::IncorrectArgumentCount(1, 2), CheckErrors::IncorrectArgumentCount(1, 2), - CheckErrors::TypeError(IntType, BoolType), - CheckErrors::TypeError(IntType, BoolType), - CheckErrors::TypeError(IntType, BoolType), - CheckErrors::TypeError(BoolType, buff_type(20)), - CheckErrors::TypeError(BoolType, buff_type(20)), - CheckErrors::TypeError(BoolType, IntType), + CheckErrors::TypeError(Box::new(IntType), Box::new(BoolType)), + CheckErrors::TypeError(Box::new(IntType), Box::new(BoolType)), + CheckErrors::TypeError(Box::new(IntType), Box::new(BoolType)), + CheckErrors::TypeError(Box::new(BoolType), Box::new(buff_type(20))), + CheckErrors::TypeError(Box::new(BoolType), Box::new(buff_type(20))), + CheckErrors::TypeError(Box::new(BoolType), Box::new(IntType)), CheckErrors::IncorrectArgumentCount(2, 3), CheckErrors::UnknownFunction("ynot".to_string()), CheckErrors::IllegalOrUnknownFunctionApplication("if".to_string()), CheckErrors::IncorrectArgumentCount(2, 1), - CheckErrors::UnionTypeError(vec![IntType, UIntType], BoolType), - CheckErrors::ExpectedSequence(UIntType), - CheckErrors::ExpectedSequence(IntType), - CheckErrors::TypeError(IntType, BoolType), + CheckErrors::UnionTypeError(vec![IntType, UIntType], Box::new(BoolType)), + CheckErrors::ExpectedSequence(Box::new(UIntType)), + CheckErrors::ExpectedSequence(Box::new(IntType)), + CheckErrors::TypeError(Box::new(IntType), Box::new(BoolType)), ]; for (good_test, expected) in good.iter().zip(expected.iter()) { @@ -1293,7 +1339,7 @@ fn test_lists() { } for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -1323,20 +1369,20 @@ fn test_buff() { "(len 1)", ]; let bad_expected = [ - CheckErrors::TypeError(BoolType, IntType), + CheckErrors::TypeError(Box::new(BoolType), Box::new(IntType)), CheckErrors::IncorrectArgumentCount(1, 2), - CheckErrors::TypeError(IntType, BoolType), - CheckErrors::TypeError(IntType, BoolType), - CheckErrors::TypeError(IntType, BoolType), - CheckErrors::TypeError(BoolType, buff_type(20)), - CheckErrors::TypeError(BoolType, IntType), + CheckErrors::TypeError(Box::new(IntType), Box::new(BoolType)), + CheckErrors::TypeError(Box::new(IntType), Box::new(BoolType)), + CheckErrors::TypeError(Box::new(IntType), Box::new(BoolType)), + CheckErrors::TypeError(Box::new(BoolType), Box::new(buff_type(20))), + CheckErrors::TypeError(Box::new(BoolType), Box::new(IntType)), CheckErrors::IncorrectArgumentCount(2, 3), CheckErrors::UnknownFunction("ynot".to_string()), CheckErrors::IllegalOrUnknownFunctionApplication("if".to_string()), CheckErrors::IncorrectArgumentCount(2, 1), - CheckErrors::UnionTypeError(vec![IntType, UIntType], BoolType), - CheckErrors::ExpectedSequence(UIntType), - CheckErrors::ExpectedSequence(IntType), + CheckErrors::UnionTypeError(vec![IntType, UIntType], Box::new(BoolType)), + CheckErrors::ExpectedSequence(Box::new(UIntType)), + CheckErrors::ExpectedSequence(Box::new(IntType)), ]; for (good_test, expected) in good.iter().zip(expected.iter()) { @@ -1347,7 +1393,7 @@ fn test_buff() { } for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -1409,7 +1455,7 @@ fn test_native_as_max_len() { CheckErrors::ValueTooLarge, ]; for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -1450,12 +1496,12 @@ fn test_native_append() { ]; let bad_expected = [ - CheckErrors::TypeError(IntType, UIntType), - CheckErrors::TypeError(UIntType, IntType), + CheckErrors::TypeError(Box::new(IntType), Box::new(UIntType)), + CheckErrors::TypeError(Box::new(UIntType), Box::new(IntType)), CheckErrors::IncorrectArgumentCount(2, 1), ]; for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -1490,12 +1536,12 @@ fn test_slice_list() { ]; let bad_expected = [ - CheckErrors::TypeError(UIntType, IntType), - CheckErrors::TypeError(UIntType, IntType), + CheckErrors::TypeError(Box::new(UIntType), Box::new(IntType)), + CheckErrors::TypeError(Box::new(UIntType), Box::new(IntType)), CheckErrors::IncorrectArgumentCount(3, 2), ]; for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -1521,12 +1567,12 @@ fn test_slice_buff() { ]; let bad_expected = [ - CheckErrors::TypeError(UIntType, IntType), - CheckErrors::TypeError(UIntType, IntType), + CheckErrors::TypeError(Box::new(UIntType), Box::new(IntType)), + CheckErrors::TypeError(Box::new(UIntType), Box::new(IntType)), CheckErrors::IncorrectArgumentCount(3, 2), ]; for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -1555,12 +1601,12 @@ fn test_slice_ascii() { ]; let bad_expected = [ - CheckErrors::TypeError(UIntType, IntType), - CheckErrors::TypeError(UIntType, IntType), + CheckErrors::TypeError(Box::new(UIntType), Box::new(IntType)), + CheckErrors::TypeError(Box::new(UIntType), Box::new(IntType)), CheckErrors::IncorrectArgumentCount(3, 2), ]; for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -1586,12 +1632,12 @@ fn test_slice_utf8() { ]; let bad_expected = [ - CheckErrors::TypeError(UIntType, IntType), - CheckErrors::TypeError(UIntType, IntType), + CheckErrors::TypeError(Box::new(UIntType), Box::new(IntType)), + CheckErrors::TypeError(Box::new(UIntType), Box::new(IntType)), CheckErrors::IncorrectArgumentCount(3, 2), ]; for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -1635,20 +1681,26 @@ fn test_replace_at_list() { let bad_expected = [ CheckErrors::TypeError( - IntType, - SequenceType(ListType(ListTypeData::new_list(IntType, 1).unwrap())), + Box::new(IntType), + Box::new(SequenceType(ListType( + ListTypeData::new_list(IntType, 1).unwrap(), + ))), ), - CheckErrors::TypeError(IntType, BoolType), - CheckErrors::TypeError(UIntType, IntType), + CheckErrors::TypeError(Box::new(IntType), Box::new(BoolType)), + CheckErrors::TypeError(Box::new(UIntType), Box::new(IntType)), CheckErrors::IncorrectArgumentCount(3, 4), CheckErrors::IncorrectArgumentCount(3, 2), CheckErrors::TypeError( - SequenceType(ListType(ListTypeData::new_list(IntType, 1).unwrap())), - SequenceType(ListType(ListTypeData::new_list(IntType, 2).unwrap())), + Box::new(SequenceType(ListType( + ListTypeData::new_list(IntType, 1).unwrap(), + ))), + Box::new(SequenceType(ListType( + ListTypeData::new_list(IntType, 2).unwrap(), + ))), ), ]; for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -1687,23 +1739,25 @@ fn test_replace_at_buff() { let buff_len_two = BufferLength::try_from(2u32).unwrap(); let bad_expected = [ CheckErrors::TypeError( - SequenceType(BufferType(buff_len.clone())), - SequenceType(ListType(ListTypeData::new_list(IntType, 1).unwrap())), + Box::new(SequenceType(BufferType(buff_len.clone()))), + Box::new(SequenceType(ListType( + ListTypeData::new_list(IntType, 1).unwrap(), + ))), ), CheckErrors::TypeError( - SequenceType(BufferType(buff_len.clone())), - SequenceType(StringType(ASCII(buff_len.clone()))), + Box::new(SequenceType(BufferType(buff_len.clone()))), + Box::new(SequenceType(StringType(ASCII(buff_len.clone())))), ), - CheckErrors::TypeError(UIntType, IntType), + CheckErrors::TypeError(Box::new(UIntType), Box::new(IntType)), CheckErrors::IncorrectArgumentCount(3, 4), CheckErrors::IncorrectArgumentCount(3, 2), CheckErrors::TypeError( - SequenceType(BufferType(buff_len)), - SequenceType(BufferType(buff_len_two)), + Box::new(SequenceType(BufferType(buff_len))), + Box::new(SequenceType(BufferType(buff_len_two))), ), ]; for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -1743,23 +1797,25 @@ fn test_replace_at_ascii() { let buff_len_two = BufferLength::try_from(2u32).unwrap(); let bad_expected = [ CheckErrors::TypeError( - SequenceType(StringType(ASCII(buff_len.clone()))), - SequenceType(ListType(ListTypeData::new_list(IntType, 1).unwrap())), + Box::new(SequenceType(StringType(ASCII(buff_len.clone())))), + Box::new(SequenceType(ListType( + ListTypeData::new_list(IntType, 1).unwrap(), + ))), ), CheckErrors::TypeError( - SequenceType(StringType(ASCII(buff_len.clone()))), - SequenceType(BufferType(buff_len.clone())), + Box::new(SequenceType(StringType(ASCII(buff_len.clone())))), + Box::new(SequenceType(BufferType(buff_len.clone()))), ), - CheckErrors::TypeError(UIntType, IntType), + CheckErrors::TypeError(Box::new(UIntType), Box::new(IntType)), CheckErrors::IncorrectArgumentCount(3, 4), CheckErrors::IncorrectArgumentCount(3, 2), CheckErrors::TypeError( - SequenceType(StringType(ASCII(buff_len))), - SequenceType(StringType(ASCII(buff_len_two))), + Box::new(SequenceType(StringType(ASCII(buff_len)))), + Box::new(SequenceType(StringType(ASCII(buff_len_two)))), ), ]; for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -1799,23 +1855,25 @@ fn test_replace_at_utf8() { let str_len_two = StringUTF8Length::try_from(2u32).unwrap(); let bad_expected = [ CheckErrors::TypeError( - SequenceType(StringType(UTF8(str_len.clone()))), - SequenceType(ListType(ListTypeData::new_list(IntType, 1).unwrap())), + Box::new(SequenceType(StringType(UTF8(str_len.clone())))), + Box::new(SequenceType(ListType( + ListTypeData::new_list(IntType, 1).unwrap(), + ))), ), CheckErrors::TypeError( - SequenceType(StringType(UTF8(str_len.clone()))), - SequenceType(BufferType(buff_len)), + Box::new(SequenceType(StringType(UTF8(str_len.clone())))), + Box::new(SequenceType(BufferType(buff_len))), ), - CheckErrors::TypeError(UIntType, IntType), + CheckErrors::TypeError(Box::new(UIntType), Box::new(IntType)), CheckErrors::IncorrectArgumentCount(3, 4), CheckErrors::IncorrectArgumentCount(3, 2), CheckErrors::TypeError( - SequenceType(StringType(UTF8(str_len))), - SequenceType(StringType(UTF8(str_len_two))), + Box::new(SequenceType(StringType(UTF8(str_len)))), + Box::new(SequenceType(StringType(UTF8(str_len_two)))), ), ]; for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -1838,12 +1896,12 @@ fn test_native_concat() { ]; let bad_expected = [ - CheckErrors::TypeError(IntType, UIntType), - CheckErrors::TypeError(UIntType, IntType), + CheckErrors::TypeError(Box::new(IntType), Box::new(UIntType)), + CheckErrors::TypeError(Box::new(UIntType), Box::new(IntType)), CheckErrors::IncorrectArgumentCount(2, 1), ]; for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -1923,8 +1981,8 @@ fn test_tuples() { ]; let bad_expected = [ - CheckErrors::TypeError(IntType, BoolType), - CheckErrors::TypeError(BoolType, IntType), + CheckErrors::TypeError(Box::new(IntType), Box::new(BoolType)), + CheckErrors::TypeError(Box::new(BoolType), Box::new(IntType)), ]; for (good_test, expected) in good.iter().zip(expected.iter()) { @@ -1935,7 +1993,7 @@ fn test_tuples() { } for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -1947,7 +2005,7 @@ fn test_empty_tuple_should_fail() { "#; assert_eq!( - mem_type_check(contract_src).unwrap_err().err, + *mem_type_check(contract_src).unwrap_err().err, CheckErrors::BadSyntaxBinding ); } @@ -2028,9 +2086,9 @@ fn test_simple_uints() { let bad = ["(> u1 1)", "(to-uint true)", "(to-int false)"]; let bad_expected = [ - CheckErrors::TypeError(UIntType, IntType), - CheckErrors::TypeError(IntType, BoolType), - CheckErrors::TypeError(UIntType, BoolType), + CheckErrors::TypeError(Box::new(UIntType), Box::new(IntType)), + CheckErrors::TypeError(Box::new(IntType), Box::new(BoolType)), + CheckErrors::TypeError(Box::new(UIntType), Box::new(BoolType)), ]; for (good_test, expected) in good.iter().zip(expected.iter()) { @@ -2039,7 +2097,7 @@ fn test_simple_uints() { } for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(&mem_type_check(bad_test).unwrap_err().err, expected); + assert_eq!(*mem_type_check(bad_test).unwrap_err().err, *expected); } } @@ -2065,12 +2123,20 @@ fn test_buffer_to_ints() { CheckErrors::IncorrectArgumentCount(1, 2), CheckErrors::IncorrectArgumentCount(1, 0), CheckErrors::TypeError( - SequenceType(BufferType(BufferLength::try_from(16_u32).unwrap())), - SequenceType(BufferType(BufferLength::try_from(17_u32).unwrap())), + Box::new(SequenceType(BufferType( + BufferLength::try_from(16_u32).unwrap(), + ))), + Box::new(SequenceType(BufferType( + BufferLength::try_from(17_u32).unwrap(), + ))), ), CheckErrors::TypeError( - SequenceType(BufferType(BufferLength::try_from(16_u32).unwrap())), - SequenceType(StringType(ASCII(BufferLength::try_from(1_u32).unwrap()))), + Box::new(SequenceType(BufferType( + BufferLength::try_from(16_u32).unwrap(), + ))), + Box::new(SequenceType(StringType(ASCII( + BufferLength::try_from(1_u32).unwrap(), + )))), ), ]; @@ -2080,7 +2146,7 @@ fn test_buffer_to_ints() { } for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(&mem_type_check(bad_test).unwrap_err().err, expected); + assert_eq!(*mem_type_check(bad_test).unwrap_err().err, *expected); } } @@ -2132,21 +2198,29 @@ fn test_string_to_ints() { CheckErrors::IncorrectArgumentCount(1, 0), CheckErrors::UnionTypeError( vec![IntType, UIntType], - SequenceType(BufferType(BufferLength::try_from(17_u32).unwrap())), + Box::new(SequenceType(BufferType( + BufferLength::try_from(17_u32).unwrap(), + ))), ), CheckErrors::UnionTypeError( vec![IntType, UIntType], - SequenceType(StringType(ASCII(BufferLength::try_from(1_u32).unwrap()))), + Box::new(SequenceType(StringType(ASCII( + BufferLength::try_from(1_u32).unwrap(), + )))), ), CheckErrors::IncorrectArgumentCount(1, 2), CheckErrors::IncorrectArgumentCount(1, 0), CheckErrors::UnionTypeError( vec![IntType, UIntType], - SequenceType(BufferType(BufferLength::try_from(17_u32).unwrap())), + Box::new(SequenceType(BufferType( + BufferLength::try_from(17_u32).unwrap(), + ))), ), CheckErrors::UnionTypeError( vec![IntType, UIntType], - SequenceType(StringType(ASCII(BufferLength::try_from(1_u32).unwrap()))), + Box::new(SequenceType(StringType(ASCII( + BufferLength::try_from(1_u32).unwrap(), + )))), ), CheckErrors::IncorrectArgumentCount(1, 2), CheckErrors::IncorrectArgumentCount(1, 0), @@ -2155,14 +2229,16 @@ fn test_string_to_ints() { TypeSignature::max_string_ascii().unwrap(), TypeSignature::max_string_utf8().unwrap(), ], - SequenceType(BufferType(BufferLength::try_from(17_u32).unwrap())), + Box::new(SequenceType(BufferType( + BufferLength::try_from(17_u32).unwrap(), + ))), ), CheckErrors::UnionTypeError( vec![ TypeSignature::max_string_ascii().unwrap(), TypeSignature::max_string_utf8().unwrap(), ], - IntType, + Box::new(IntType), ), CheckErrors::IncorrectArgumentCount(1, 2), CheckErrors::IncorrectArgumentCount(1, 0), @@ -2171,14 +2247,16 @@ fn test_string_to_ints() { TypeSignature::max_string_ascii().unwrap(), TypeSignature::max_string_utf8().unwrap(), ], - SequenceType(BufferType(BufferLength::try_from(17_u32).unwrap())), + Box::new(SequenceType(BufferType( + BufferLength::try_from(17_u32).unwrap(), + ))), ), CheckErrors::UnionTypeError( vec![ TypeSignature::max_string_ascii().unwrap(), TypeSignature::max_string_utf8().unwrap(), ], - IntType, + Box::new(IntType), ), ]; @@ -2188,7 +2266,7 @@ fn test_string_to_ints() { } for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(&mem_type_check(bad_test).unwrap_err().err, expected); + assert_eq!(*mem_type_check(bad_test).unwrap_err().err, *expected); } } @@ -2229,10 +2307,14 @@ fn test_response_inference(#[case] version: ClarityVersion, #[case] epoch: Stack let bad_expected = [ CheckErrors::TypeError( - TypeSignature::from_string("(response bool int)", version, epoch), - BoolType, + Box::new(TypeSignature::from_string( + "(response bool int)", + version, + epoch, + )), + Box::new(BoolType), ), - CheckErrors::ReturnTypesMustMatch(IntType, BoolType), + CheckErrors::ReturnTypesMustMatch(Box::new(IntType), Box::new(BoolType)), CheckErrors::CouldNotDetermineResponseOkType, ]; @@ -2242,7 +2324,7 @@ fn test_response_inference(#[case] version: ClarityVersion, #[case] epoch: Stack } for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(&mem_type_check(bad_test).unwrap_err().err, expected); + assert_eq!(*mem_type_check(bad_test).unwrap_err().err, *expected); } } @@ -2350,20 +2432,20 @@ fn test_options(#[case] version: ClarityVersion, #[case] epoch: StacksEpochId) { if version < ClarityVersion::Clarity2 { assert!( - match mem_run_analysis(contract, version, epoch).unwrap_err().err { + match *mem_run_analysis(contract, version, epoch).unwrap_err().err { CheckErrors::TypeError(t1, t2) => { - t1 == TypeSignature::from_string("(optional bool)", version, epoch) - && t2 == TypeSignature::from_string("(optional int)", version, epoch) + *t1 == TypeSignature::from_string("(optional bool)", version, epoch) + && *t2 == TypeSignature::from_string("(optional int)", version, epoch) } _ => false, } ); } else { assert!( - match mem_run_analysis(contract, version, epoch).unwrap_err().err { + match *mem_run_analysis(contract, version, epoch).unwrap_err().err { CheckErrors::TypeError(t1, t2) => { - t1 == TypeSignature::from_string("bool", version, epoch) - && t2 == TypeSignature::from_string("int", version, epoch) + *t1 == TypeSignature::from_string("bool", version, epoch) + && *t2 == TypeSignature::from_string("int", version, epoch) } _ => false, } @@ -2378,7 +2460,7 @@ fn test_list_nones() { (let ((a (list none none none))) (print a)))"; assert_eq!( "(list 3 (optional UnknownType))", - &format!("{}", mem_type_check(contract).unwrap().0.unwrap()) + &format!("{}", mem_type_check(contract).unwrap().0.unwrap()), ); } @@ -2468,7 +2550,10 @@ fn test_missing_value_on_declaration_should_fail() { "#; let res = mem_type_check(contract_src).unwrap_err(); - assert!(matches!(res.err, CheckErrors::IncorrectArgumentCount(_, _))); + assert!(matches!( + *res.err, + CheckErrors::IncorrectArgumentCount(_, _) + )); } #[test] @@ -2478,7 +2563,7 @@ fn test_mismatching_type_on_declaration_should_fail() { "#; let res = mem_type_check(contract_src).unwrap_err(); - assert!(matches!(res.err, CheckErrors::TypeError(_, _))); + assert!(matches!(*res.err, CheckErrors::TypeError(_, _))); } #[test] @@ -2494,7 +2579,7 @@ fn test_mismatching_type_on_update_should_fail() { "#; let res = mem_type_check(contract_src).unwrap_err(); - assert!(matches!(res.err, CheckErrors::TypeError(_, _))); + assert!(matches!(*res.err, CheckErrors::TypeError(_, _))); } #[test] @@ -2506,7 +2591,7 @@ fn test_direct_access_to_persisted_var_should_fail() { "#; let res = mem_type_check(contract_src).unwrap_err(); - assert!(matches!(res.err, CheckErrors::UndefinedVariable(_))); + assert!(matches!(*res.err, CheckErrors::UndefinedVariable(_))); } #[test] @@ -2521,7 +2606,7 @@ fn test_data_var_shadowed_by_let_should_fail() { "#; let res = mem_type_check(contract_src).unwrap_err(); - assert!(matches!(res.err, CheckErrors::NameAlreadyUsed(_))); + assert!(matches!(*res.err, CheckErrors::NameAlreadyUsed(_))); } #[test] @@ -2534,7 +2619,7 @@ fn test_mutating_unknown_data_var_should_fail() { "#; let res = mem_type_check(contract_src).unwrap_err(); - assert!(matches!(res.err, CheckErrors::NoSuchDataVariable(_))); + assert!(matches!(*res.err, CheckErrors::NoSuchDataVariable(_))); } #[test] @@ -2545,7 +2630,7 @@ fn test_accessing_unknown_data_var_should_fail() { "#; let res = mem_type_check(contract_src).unwrap_err(); - assert!(matches!(res.err, CheckErrors::NoSuchDataVariable(_))); + assert!(matches!(*res.err, CheckErrors::NoSuchDataVariable(_))); } #[test] @@ -2556,7 +2641,7 @@ fn test_let_shadowed_by_let_should_fail() { "#; let res = mem_type_check(contract_src).unwrap_err(); - assert!(matches!(res.err, CheckErrors::NameAlreadyUsed(_))); + assert!(matches!(*res.err, CheckErrors::NameAlreadyUsed(_))); } #[test] @@ -2568,7 +2653,7 @@ fn test_let_shadowed_by_nested_let_should_fail() { "#; let res = mem_type_check(contract_src).unwrap_err(); - assert!(matches!(res.err, CheckErrors::NameAlreadyUsed(_))); + assert!(matches!(*res.err, CheckErrors::NameAlreadyUsed(_))); } #[test] @@ -2581,7 +2666,7 @@ fn test_define_constant_shadowed_by_let_should_fail() { "#; let res = mem_type_check(contract_src).unwrap_err(); - assert!(matches!(res.err, CheckErrors::NameAlreadyUsed(_))); + assert!(matches!(*res.err, CheckErrors::NameAlreadyUsed(_))); } #[test] @@ -2593,7 +2678,7 @@ fn test_define_constant_shadowed_by_argument_should_fail() { "#; let res = mem_type_check(contract_src).unwrap_err(); - assert!(matches!(res.err, CheckErrors::NameAlreadyUsed(_))); + assert!(matches!(*res.err, CheckErrors::NameAlreadyUsed(_))); } #[test] @@ -2793,7 +2878,7 @@ fn test_fetch_entry_mismatching_type_signatures() { ({case}))" ); let res = mem_type_check(&contract_src).unwrap_err(); - assert!(matches!(res.err, CheckErrors::TypeError(_, _))); + assert!(matches!(*res.err, CheckErrors::TypeError(_, _))); } } @@ -2808,7 +2893,7 @@ fn test_fetch_entry_unbound_variables() { ({case}))" ); let res = mem_type_check(&contract_src).unwrap_err(); - assert!(matches!(res.err, CheckErrors::UndefinedVariable(_))); + assert!(matches!(*res.err, CheckErrors::UndefinedVariable(_))); } } @@ -2850,7 +2935,7 @@ fn test_insert_entry_mismatching_type_signatures() { ({case}))" ); let res = mem_type_check(&contract_src).unwrap_err(); - assert!(matches!(res.err, CheckErrors::TypeError(_, _))); + assert!(matches!(*res.err, CheckErrors::TypeError(_, _))); } } @@ -2868,7 +2953,7 @@ fn test_insert_entry_unbound_variables() { ({case}))" ); let res = mem_type_check(&contract_src).unwrap_err(); - assert!(matches!(res.err, CheckErrors::UndefinedVariable(_))); + assert!(matches!(*res.err, CheckErrors::UndefinedVariable(_))); } } @@ -2908,7 +2993,7 @@ fn test_delete_entry_mismatching_type_signatures() { ({case}))" ); let res = mem_type_check(&contract_src).unwrap_err(); - assert!(matches!(res.err, CheckErrors::TypeError(_, _))); + assert!(matches!(*res.err, CheckErrors::TypeError(_, _))); } } @@ -2923,7 +3008,7 @@ fn test_delete_entry_unbound_variables() { ({case}))" ); let res = mem_type_check(&contract_src).unwrap_err(); - assert!(matches!(res.err, CheckErrors::UndefinedVariable(_))); + assert!(matches!(*res.err, CheckErrors::UndefinedVariable(_))); } } @@ -2967,7 +3052,7 @@ fn test_set_entry_mismatching_type_signatures() { ({case}))" ); let res = mem_type_check(&contract_src).unwrap_err(); - assert!(matches!(res.err, CheckErrors::TypeError(_, _))); + assert!(matches!(*res.err, CheckErrors::TypeError(_, _))); } } @@ -2985,7 +3070,7 @@ fn test_set_entry_unbound_variables() { ({case}))" ); let res = mem_type_check(&contract_src).unwrap_err(); - assert!(matches!(res.err, CheckErrors::UndefinedVariable(_))); + assert!(matches!(*res.err, CheckErrors::UndefinedVariable(_))); } } @@ -3101,7 +3186,7 @@ fn test_buff_negative_len() { (func 0x00)"; let res = mem_type_check(contract_src).unwrap_err(); - assert!(matches!(res.err, CheckErrors::BadSyntaxBinding)); + assert!(matches!(*res.err, CheckErrors::BadSyntaxBinding)); } #[test] @@ -3110,7 +3195,7 @@ fn test_string_ascii_negative_len() { (func \"\")"; let res = mem_type_check(contract_src).unwrap_err(); - assert!(matches!(res.err, CheckErrors::BadSyntaxBinding)); + assert!(matches!(*res.err, CheckErrors::BadSyntaxBinding)); } #[test] @@ -3119,7 +3204,7 @@ fn test_string_utf8_negative_len() { (func u\"\")"; let res = mem_type_check(contract_src).unwrap_err(); - assert!(matches!(res.err, CheckErrors::BadSyntaxBinding)); + assert!(matches!(*res.err, CheckErrors::BadSyntaxBinding)); } #[test] @@ -3175,7 +3260,7 @@ fn test_comparison_types() { ))), SequenceType(BufferType(BufferLength::try_from(1048576_u32).unwrap())), ], - PrincipalType, + Box::new(PrincipalType), ), CheckErrors::UnionTypeError( vec![ @@ -3189,23 +3274,41 @@ fn test_comparison_types() { ))), SequenceType(BufferType(BufferLength::try_from(1048576_u32).unwrap())), ], - SequenceType(ListType(ListTypeData::new_list(IntType, 3).unwrap())), + Box::new(SequenceType(ListType( + ListTypeData::new_list(IntType, 3).unwrap(), + ))), ), CheckErrors::TypeError( - SequenceType(StringType(UTF8(StringUTF8Length::try_from(3u32).unwrap()))), - SequenceType(StringType(ASCII(BufferLength::try_from(2_u32).unwrap()))), + Box::new(SequenceType(StringType(UTF8( + StringUTF8Length::try_from(3u32).unwrap(), + )))), + Box::new(SequenceType(StringType(ASCII( + BufferLength::try_from(2_u32).unwrap(), + )))), ), CheckErrors::TypeError( - SequenceType(StringType(ASCII(BufferLength::try_from(3_u32).unwrap()))), - SequenceType(BufferType(BufferLength::try_from(2_u32).unwrap())), + Box::new(SequenceType(StringType(ASCII( + BufferLength::try_from(3_u32).unwrap(), + )))), + Box::new(SequenceType(BufferType( + BufferLength::try_from(2_u32).unwrap(), + ))), ), CheckErrors::TypeError( - SequenceType(BufferType(BufferLength::try_from(2_u32).unwrap())), - SequenceType(StringType(UTF8(StringUTF8Length::try_from(3u32).unwrap()))), + Box::new(SequenceType(BufferType( + BufferLength::try_from(2_u32).unwrap(), + ))), + Box::new(SequenceType(StringType(UTF8( + StringUTF8Length::try_from(3u32).unwrap(), + )))), ), CheckErrors::TypeError( - SequenceType(BufferType(BufferLength::try_from(2_u32).unwrap())), - SequenceType(StringType(ASCII(BufferLength::try_from(3_u32).unwrap()))), + Box::new(SequenceType(BufferType( + BufferLength::try_from(2_u32).unwrap(), + ))), + Box::new(SequenceType(StringType(ASCII( + BufferLength::try_from(3_u32).unwrap(), + )))), ), CheckErrors::IncorrectArgumentCount(2, 0), CheckErrors::IncorrectArgumentCount(2, 1), @@ -3213,7 +3316,7 @@ fn test_comparison_types() { ]; for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -3240,7 +3343,10 @@ fn test_principal_destruct() { let bad_expected = [ CheckErrors::IncorrectArgumentCount(1, 2), CheckErrors::IncorrectArgumentCount(1, 0), - CheckErrors::TypeError(TypeSignature::PrincipalType, BUFF_1.clone()), + CheckErrors::TypeError( + Box::new(TypeSignature::PrincipalType), + Box::new(BUFF_1.clone()), + ), ]; for (good_test, expected) in good.iter().zip(expected.iter()) { @@ -3251,7 +3357,7 @@ fn test_principal_destruct() { } for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -3301,32 +3407,32 @@ fn test_principal_construct() { // The first buffer is too long, should be `(buff 1)`. ( r#"(principal-construct? 0xfa6bf38ed557fe417333710d6033e9419391a320 0xfa6bf38ed557fe417333710d6033e9419391a320)"#, - CheckErrors::TypeError(BUFF_1.clone(), BUFF_20.clone()), + CheckErrors::TypeError(Box::new(BUFF_1.clone()), Box::new(BUFF_20.clone())), ), // The second buffer is too long, should be `(buff 20)`. ( r#"(principal-construct? 0x22 0xfa6bf38ed557fe417333710d6033e9419391a32009)"#, - CheckErrors::TypeError(BUFF_20.clone(), BUFF_21.clone()), + CheckErrors::TypeError(Box::new(BUFF_20.clone()), Box::new(BUFF_21.clone())), ), // `int` argument instead of `(buff 1)` for version. ( r#"(principal-construct? 22 0xfa6bf38ed557fe417333710d6033e9419391a320)"#, - CheckErrors::TypeError(BUFF_1.clone(), IntType), + CheckErrors::TypeError(Box::new(BUFF_1.clone()), Box::new(IntType.clone())), ), // `name` argument is too long ( r#"(principal-construct? 0x22 0xfa6bf38ed557fe417333710d6033e9419391a320 "foooooooooooooooooooooooooooooooooooooooo")"#, CheckErrors::TypeError( - TypeSignature::contract_name_string_ascii_type().unwrap(), - TypeSignature::bound_string_ascii_type(41).unwrap(), + Box::new(TypeSignature::contract_name_string_ascii_type().unwrap()), + Box::new(TypeSignature::bound_string_ascii_type(41).unwrap()), ), ), // bad argument type for `name` ( r#"(principal-construct? 0x22 0xfa6bf38ed557fe417333710d6033e9419391a320 u123)"#, CheckErrors::TypeError( - TypeSignature::contract_name_string_ascii_type().unwrap(), - UIntType, + Box::new(TypeSignature::contract_name_string_ascii_type().unwrap()), + Box::new(UIntType), ), ), // too many arguments @@ -3337,7 +3443,7 @@ fn test_principal_construct() { ]; for (bad_test, expected) in bad_pairs.iter() { - assert_eq!(expected, &type_check_helper(bad_test).unwrap_err().err); + assert_eq!(*expected, *type_check_helper(bad_test).unwrap_err().err); } } @@ -3387,14 +3493,14 @@ fn test_trait_args() { let contract_identifier = QualifiedContractIdentifier::transient(); let bad_expected = [CheckErrors::IncompatibleTrait( - TraitIdentifier { + Box::new(TraitIdentifier { name: ClarityName::from("trait-foo"), contract_identifier: contract_identifier.clone(), - }, - TraitIdentifier { + }), + Box::new(TraitIdentifier { name: ClarityName::from("trait-bar"), contract_identifier, - }, + }), )]; for good_test in good.iter() { @@ -3402,7 +3508,7 @@ fn test_trait_args() { } for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { - assert_eq!(expected, &mem_type_check(bad_test).unwrap_err().err); + assert_eq!(*expected, *mem_type_check(bad_test).unwrap_err().err); } } @@ -3553,28 +3659,36 @@ fn test_list_arg(#[case] version: ClarityVersion, #[case] epoch: StacksEpochId) ]; let bad_expected = [ CheckErrors::TypeError( - TypeSignature::list_of(TypeSignature::IntType, 3).unwrap(), - TypeSignature::list_of(TypeSignature::IntType, 4).unwrap(), + Box::new(TypeSignature::list_of(TypeSignature::IntType, 3).unwrap()), + Box::new(TypeSignature::list_of(TypeSignature::IntType, 4).unwrap()), ), CheckErrors::TypeError( - TypeSignature::list_of(TypeSignature::IntType, 3).unwrap(), - TypeSignature::list_of(TypeSignature::UIntType, 1).unwrap(), + Box::new(TypeSignature::list_of(TypeSignature::IntType, 3).unwrap()), + Box::new(TypeSignature::list_of(TypeSignature::UIntType, 1).unwrap()), ), CheckErrors::TypeError( - TypeSignature::list_of(TypeSignature::IntType, 3).unwrap(), - TypeSignature::list_of(TypeSignature::list_of(TypeSignature::NoType, 0).unwrap(), 1) + Box::new(TypeSignature::list_of(TypeSignature::IntType, 3).unwrap()), + Box::new( + TypeSignature::list_of( + TypeSignature::list_of(TypeSignature::NoType, 0).unwrap(), + 1, + ) .unwrap(), + ), ), ]; let bad_expected2 = [ CheckErrors::TypeError( - TypeSignature::list_of(TypeSignature::IntType, 3).unwrap(), - TypeSignature::list_of(TypeSignature::IntType, 4).unwrap(), + Box::new(TypeSignature::list_of(TypeSignature::IntType, 3).unwrap()), + Box::new(TypeSignature::list_of(TypeSignature::IntType, 4).unwrap()), ), - CheckErrors::TypeError(TypeSignature::IntType, TypeSignature::UIntType), CheckErrors::TypeError( - TypeSignature::IntType, - TypeSignature::list_of(TypeSignature::NoType, 0).unwrap(), + Box::new(TypeSignature::IntType), + Box::new(TypeSignature::UIntType), + ), + CheckErrors::TypeError( + Box::new(TypeSignature::IntType), + Box::new(TypeSignature::list_of(TypeSignature::NoType, 0).unwrap()), ), ]; @@ -3587,8 +3701,8 @@ fn test_list_arg(#[case] version: ClarityVersion, #[case] epoch: StacksEpochId) .iter(), ) { assert_eq!( - expected, - &mem_run_analysis(bad_test, version, epoch).unwrap_err().err + *expected, + *mem_run_analysis(bad_test, version, epoch).unwrap_err().err ); } } diff --git a/clarity/src/vm/ast/definition_sorter/tests.rs b/clarity/src/vm/ast/definition_sorter/tests.rs index 0142052c507..9bbb3211781 100644 --- a/clarity/src/vm/ast/definition_sorter/tests.rs +++ b/clarity/src/vm/ast/definition_sorter/tests.rs @@ -63,7 +63,7 @@ fn should_succeed_sorting_contract_case_1(#[case] version: ClarityVersion) { (define-private (wrapped-kv-del (key int)) (kv-del key)) (define-private (kv-del (key int)) - (begin + (begin (map-delete kv-store { key: key }) key)) (define-map kv-store { key: int } { value: int }) @@ -96,7 +96,7 @@ fn should_raise_dependency_cycle_case_1(#[case] version: ClarityVersion) { "#; let err = run_scoped_parsing_helper(contract, version).unwrap_err(); - assert!(matches!(err.err, ParseErrors::CircularReference(_))); + assert!(matches!(*err.err, ParseErrors::CircularReference(_))); } #[apply(test_clarity_versions_definition_sorter)] @@ -109,14 +109,14 @@ fn should_raise_dependency_cycle_case_2(#[case] version: ClarityVersion) { "#; let err = run_scoped_parsing_helper(contract, version).unwrap_err(); - assert!(matches!(err.err, ParseErrors::CircularReference(_))); + assert!(matches!(*err.err, ParseErrors::CircularReference(_))); } #[apply(test_clarity_versions_definition_sorter)] fn should_not_raise_dependency_cycle_case_let(#[case] version: ClarityVersion) { let contract = r#" (define-private (foo (x int)) (begin (bar 1) 1)) - (define-private (bar (x int)) (let ((foo 1)) (+ 1 x))) + (define-private (bar (x int)) (let ((foo 1)) (+ 1 x))) "#; run_scoped_parsing_helper(contract, version).unwrap(); @@ -127,11 +127,11 @@ fn should_not_raise_dependency_cycle_case_let(#[case] version: ClarityVersion) { fn should_raise_dependency_cycle_case_let(#[case] version: ClarityVersion) { let contract = r#" (define-private (foo (x int)) (begin (bar 1) 1)) - (define-private (bar (x int)) (let ((baz (foo 1))) (+ 1 x))) + (define-private (bar (x int)) (let ((baz (foo 1))) (+ 1 x))) "#; let err = run_scoped_parsing_helper(contract, version).unwrap_err(); - assert!(matches!(err.err, ParseErrors::CircularReference(_))); + assert!(matches!(*err.err, ParseErrors::CircularReference(_))); } #[apply(test_clarity_versions_definition_sorter)] @@ -149,18 +149,18 @@ fn should_not_raise_dependency_cycle_case_get(#[case] version: ClarityVersion) { fn should_raise_dependency_cycle_case_get(#[case] version: ClarityVersion) { let contract = r#" (define-private (foo (x int)) (begin (bar 1) 1)) - (define-private (bar (x int)) (let ((res (foo 1))) (+ 1 x))) + (define-private (bar (x int)) (let ((res (foo 1))) (+ 1 x))) "#; let err = run_scoped_parsing_helper(contract, version).unwrap_err(); - assert!(matches!(err.err, ParseErrors::CircularReference(_))); + assert!(matches!(*err.err, ParseErrors::CircularReference(_))); } #[apply(test_clarity_versions_definition_sorter)] fn should_not_raise_dependency_cycle_case_fetch_entry(#[case] version: ClarityVersion) { let contract = r#" (define-private (foo (x int)) (begin (bar 1) 1)) - (define-private (bar (x int)) (map-get? kv-store { foo: 1 })) + (define-private (bar (x int)) (map-get? kv-store { foo: 1 })) (define-map kv-store { foo: int } { bar: int }) "#; @@ -172,19 +172,19 @@ fn should_not_raise_dependency_cycle_case_fetch_entry(#[case] version: ClarityVe fn should_raise_dependency_cycle_case_fetch_entry(#[case] version: ClarityVersion) { let contract = r#" (define-private (foo (x int)) (+ (bar x) x)) - (define-private (bar (x int)) (map-get? kv-store { foo: (foo 1) })) + (define-private (bar (x int)) (map-get? kv-store { foo: (foo 1) })) (define-map kv-store { foo: int } { bar: int }) "#; let err = run_scoped_parsing_helper(contract, version).unwrap_err(); - assert!(matches!(err.err, ParseErrors::CircularReference(_))); + assert!(matches!(*err.err, ParseErrors::CircularReference(_))); } #[apply(test_clarity_versions_definition_sorter)] fn should_not_raise_dependency_cycle_case_delete_entry(#[case] version: ClarityVersion) { let contract = r#" (define-private (foo (x int)) (begin (bar 1) 1)) - (define-private (bar (x int)) (map-delete kv-store (tuple (foo 1)))) + (define-private (bar (x int)) (map-delete kv-store (tuple (foo 1)))) (define-map kv-store { foo: int } { bar: int }) "#; @@ -196,19 +196,19 @@ fn should_not_raise_dependency_cycle_case_delete_entry(#[case] version: ClarityV fn should_raise_dependency_cycle_case_delete_entry(#[case] version: ClarityVersion) { let contract = r#" (define-private (foo (x int)) (+ (bar x) x)) - (define-private (bar (x int)) (map-delete kv-store (tuple (foo (foo 1))))) + (define-private (bar (x int)) (map-delete kv-store (tuple (foo (foo 1))))) (define-map kv-store { foo: int } { bar: int }) "#; let err = run_scoped_parsing_helper(contract, version).unwrap_err(); - assert!(matches!(err.err, ParseErrors::CircularReference(_))); + assert!(matches!(*err.err, ParseErrors::CircularReference(_))); } #[apply(test_clarity_versions_definition_sorter)] fn should_not_raise_dependency_cycle_case_set_entry(#[case] version: ClarityVersion) { let contract = r#" (define-private (foo (x int)) (begin (bar 1) 1)) - (define-private (bar (x int)) (map-set kv-store { foo: 1 } { bar: 3 })) + (define-private (bar (x int)) (map-set kv-store { foo: 1 } { bar: 3 })) (define-map kv-store { foo: int } { bar: int }) "#; @@ -220,19 +220,19 @@ fn should_not_raise_dependency_cycle_case_set_entry(#[case] version: ClarityVers fn should_raise_dependency_cycle_case_set_entry(#[case] version: ClarityVersion) { let contract = r#" (define-private (foo (x int)) (+ (bar x) x)) - (define-private (bar (x int)) (map-set kv-store { foo: 1 } { bar: (foo 1) })) + (define-private (bar (x int)) (map-set kv-store { foo: 1 } { bar: (foo 1) })) (define-map kv-store { foo: int } { bar: int }) "#; let err = run_scoped_parsing_helper(contract, version).unwrap_err(); - assert!(matches!(err.err, ParseErrors::CircularReference(_))); + assert!(matches!(*err.err, ParseErrors::CircularReference(_))); } #[apply(test_clarity_versions_definition_sorter)] fn should_not_raise_dependency_cycle_case_insert_entry(#[case] version: ClarityVersion) { let contract = r#" (define-private (foo (x int)) (begin (bar 1) 1)) - (define-private (bar (x int)) (map-insert kv-store { foo: 1 } { bar: 3 })) + (define-private (bar (x int)) (map-insert kv-store { foo: 1 } { bar: 3 })) (define-map kv-store { foo: int } { bar: int }) "#; @@ -249,18 +249,18 @@ fn should_raise_dependency_cycle_case_insert_entry(#[case] version: ClarityVersi "#; let err = run_scoped_parsing_helper(contract, version).unwrap_err(); - assert!(matches!(err.err, ParseErrors::CircularReference(_))); + assert!(matches!(*err.err, ParseErrors::CircularReference(_))); } #[apply(test_clarity_versions_definition_sorter)] fn should_raise_dependency_cycle_case_fetch_contract_entry(#[case] version: ClarityVersion) { let contract = r#" (define-private (foo (x int)) (+ (bar x) x)) - (define-private (bar (x int)) (map-get? kv-store { foo: (foo 1) })) + (define-private (bar (x int)) (map-get? kv-store { foo: (foo 1) })) "#; let err = run_scoped_parsing_helper(contract, version).unwrap_err(); - assert!(matches!(err.err, ParseErrors::CircularReference(_))); + assert!(matches!(*err.err, ParseErrors::CircularReference(_))); } #[apply(test_clarity_versions_definition_sorter)] diff --git a/clarity/src/vm/ast/mod.rs b/clarity/src/vm/ast/mod.rs index d269403d776..ccb78536411 100644 --- a/clarity/src/vm/ast/mod.rs +++ b/clarity/src/vm/ast/mod.rs @@ -416,7 +416,7 @@ mod test { cost_addition_count: 1, }; - assert_eq!(&expected_err, &err.err); + assert_eq!(expected_err, *err.err); assert_eq!(expected_list_cost_state, cost_track); // with new rules, this is now VaryExpressionStackDepthTooDeep @@ -438,7 +438,7 @@ mod test { cost_addition_count: 1, }; - assert_eq!(&expected_err, &err.err); + assert_eq!(expected_err, *err.err); assert_eq!(expected_list_cost_state, cost_track); // you cannot do the same for tuples! @@ -474,7 +474,7 @@ mod test { cost_addition_count: 1, }; - assert_eq!(&expected_err, &err.err); + assert_eq!(expected_err, *err.err); assert_eq!(expected_list_cost_state, cost_track); } @@ -518,7 +518,7 @@ mod test { cost_addition_count: 1, }; - assert_eq!(&expected_err, &err.err); + assert_eq!(expected_err, *err.err); assert_eq!(expected_list_cost_state, cost_track); // in 2.1, this is still ExpressionStackDepthTooDeep @@ -540,7 +540,7 @@ mod test { cost_addition_count: 1, }; - assert_eq!(&expected_err, &err.err); + assert_eq!(expected_err, *err.err); assert_eq!(expected_list_cost_state, cost_track); // in 2.1, ASTRules::Typical is ignored -- this still fails to parse @@ -562,7 +562,7 @@ mod test { cost_addition_count: 1, }; - assert_eq!(&expected_err, &err.err); + assert_eq!(expected_err, *err.err); assert_eq!(expected_list_cost_state, cost_track); // in 2.1, ASTRules::PrecheckSize is still ignored -- this still fails to parse @@ -584,7 +584,7 @@ mod test { cost_addition_count: 1, }; - assert_eq!(&expected_err, &err.err); + assert_eq!(expected_err, *err.err); assert_eq!(expected_list_cost_state, cost_track); } } diff --git a/clarity/src/vm/ast/parser/v1.rs b/clarity/src/vm/ast/parser/v1.rs index d767e5c0923..feb59798956 100644 --- a/clarity/src/vm/ast/parser/v1.rs +++ b/clarity/src/vm/ast/parser/v1.rs @@ -1056,56 +1056,56 @@ mod test { ); assert!(matches!( - ast::parser::v1::parse(split_tokens).unwrap_err().err, + *ast::parser::v1::parse(split_tokens).unwrap_err().err, ParseErrors::SeparatorExpected(_) )); assert!(matches!( - ast::parser::v1::parse(too_much_closure).unwrap_err().err, + *ast::parser::v1::parse(too_much_closure).unwrap_err().err, ParseErrors::ClosingParenthesisUnexpected )); assert!(matches!( - ast::parser::v1::parse(not_enough_closure).unwrap_err().err, + *ast::parser::v1::parse(not_enough_closure).unwrap_err().err, ParseErrors::ClosingParenthesisExpected )); assert!(matches!( - ast::parser::v1::parse(middle_hash).unwrap_err().err, + *ast::parser::v1::parse(middle_hash).unwrap_err().err, ParseErrors::FailedParsingRemainder(_) )); assert!(matches!( - ast::parser::v1::parse(unicode).unwrap_err().err, + *ast::parser::v1::parse(unicode).unwrap_err().err, ParseErrors::FailedParsingRemainder(_) )); assert!(matches!( - ast::parser::v1::parse(name_with_dot).unwrap_err().err, + *ast::parser::v1::parse(name_with_dot).unwrap_err().err, ParseErrors::SeparatorExpected(_) )); assert!(matches!( - ast::parser::v1::parse(wrong_tuple_literal_close) + *ast::parser::v1::parse(wrong_tuple_literal_close) .unwrap_err() .err, ParseErrors::ClosingTupleLiteralExpected )); assert!(matches!( - ast::parser::v1::parse(wrong_list_close).unwrap_err().err, + *ast::parser::v1::parse(wrong_list_close).unwrap_err().err, ParseErrors::ClosingParenthesisExpected )); assert!(matches!( - ast::parser::v1::parse(extra_tuple_literal_close) + *ast::parser::v1::parse(extra_tuple_literal_close) .unwrap_err() .err, ParseErrors::ClosingTupleLiteralUnexpected )); assert!(matches!( - ast::parser::v1::parse(unexpected_comma).unwrap_err().err, + *ast::parser::v1::parse(unexpected_comma).unwrap_err().err, ParseErrors::CommaSeparatorUnexpected )); @@ -1113,91 +1113,91 @@ mod test { ast::parser::v1::parse(tuple_comma_no_space).unwrap(); assert!(matches!( - ast::parser::v1::parse(tuple_colon_no_space) + *ast::parser::v1::parse(tuple_colon_no_space) .unwrap_err() .err, ParseErrors::SeparatorExpectedAfterColon(_) )); assert!(matches!( - ast::parser::v1::parse(shorthand_tuple).unwrap_err().err, + *ast::parser::v1::parse(shorthand_tuple).unwrap_err().err, ParseErrors::TupleColonExpected(_) )); assert!(matches!( - ast::parser::v1::parse(shorthand_tuple_dangling_comma) + *ast::parser::v1::parse(shorthand_tuple_dangling_comma) .unwrap_err() .err, ParseErrors::TupleItemExpected(_) )); assert!(matches!( - ast::parser::v1::parse(decorative_colon_on_value) + *ast::parser::v1::parse(decorative_colon_on_value) .unwrap_err() .err, ParseErrors::TupleCommaExpected(_) )); assert!(matches!( - ast::parser::v1::parse(tuple_literal_colon_after_comma) + *ast::parser::v1::parse(tuple_literal_colon_after_comma) .unwrap_err() .err, ParseErrors::TupleItemExpected(_) )); assert!(matches!( - ast::parser::v1::parse(empty_tuple_literal_comma) + *ast::parser::v1::parse(empty_tuple_literal_comma) .unwrap_err() .err, ParseErrors::TupleItemExpected(_) )); assert!(matches!( - ast::parser::v1::parse(empty_tuple_literal_colon) + *ast::parser::v1::parse(empty_tuple_literal_colon) .unwrap_err() .err, ParseErrors::TupleItemExpected(_) )); assert!(matches!( - ast::parser::v1::parse(legacy_boolean_literals) + *ast::parser::v1::parse(legacy_boolean_literals) .unwrap_err() .err, ParseErrors::FailedParsingRemainder(_) )); assert!(matches!( - ast::parser::v1::parse(function_with_CR).unwrap_err().err, + *ast::parser::v1::parse(function_with_CR).unwrap_err().err, ParseErrors::FailedParsingRemainder(_) )); assert!(matches!( - ast::parser::v1::parse(function_with_CRLF).unwrap_err().err, + *ast::parser::v1::parse(function_with_CRLF).unwrap_err().err, ParseErrors::FailedParsingRemainder(_) )); assert!(matches!( - ast::parser::v1::parse(function_with_NEL).unwrap_err().err, + *ast::parser::v1::parse(function_with_NEL).unwrap_err().err, ParseErrors::FailedParsingRemainder(_) )); assert!(matches!( - ast::parser::v1::parse(function_with_LS).unwrap_err().err, + *ast::parser::v1::parse(function_with_LS).unwrap_err().err, ParseErrors::FailedParsingRemainder(_) )); assert!(matches!( - ast::parser::v1::parse(function_with_PS).unwrap_err().err, + *ast::parser::v1::parse(function_with_PS).unwrap_err().err, ParseErrors::FailedParsingRemainder(_) )); ast::parser::v1::parse(function_with_LF).unwrap(); assert!(matches!( - ast::parser::v1::parse(string_with_invalid_escape) + *ast::parser::v1::parse(string_with_invalid_escape) .unwrap_err() .err, ParseErrors::InvalidEscaping )); assert!(matches!( - ast::parser::v1::parse(ascii_string_with_unicode_escape) + *ast::parser::v1::parse(ascii_string_with_unicode_escape) .unwrap_err() .err, ParseErrors::InvalidEscaping @@ -1224,14 +1224,14 @@ mod test { ); assert!(matches!( - ast::parser::v1::parse(&exceeds_stack_depth_tuple) + *ast::parser::v1::parse(&exceeds_stack_depth_tuple) .unwrap_err() .err, ParseErrors::VaryExpressionStackDepthTooDeep )); assert!(matches!( - ast::parser::v1::parse(&exceeds_stack_depth_list) + *ast::parser::v1::parse(&exceeds_stack_depth_list) .unwrap_err() .err, ParseErrors::VaryExpressionStackDepthTooDeep @@ -1242,7 +1242,7 @@ mod test { fn test_long_contract_name() { let long_contract_name = "(define-private (transfer (id uint) (receiver principal)) (contract-call? 'SP3D6PV2ACBPEKYJTCMH7HEN02KP87QSP8KTEH335.megapont-robot-expansion-nftSPNWZ5V2TPWGQGVDR6T7B6RQ4XMGZ4PXTEE0VQ0S.guests-hosted-stacks-parrots transfer id tx-sender receiver))"; assert!(matches!( - ast::parser::v1::parse(long_contract_name).unwrap_err().err, + *ast::parser::v1::parse(long_contract_name).unwrap_err().err, ParseErrors::SeparatorExpected(_) )); } diff --git a/clarity/src/vm/ast/parser/v2/mod.rs b/clarity/src/vm/ast/parser/v2/mod.rs index 03a62f9560c..8d08cf04ae2 100644 --- a/clarity/src/vm/ast/parser/v2/mod.rs +++ b/clarity/src/vm/ast/parser/v2/mod.rs @@ -3533,7 +3533,7 @@ mod tests { fn test_parse_fail_fast() { match parse("42g !ok") { Ok(_) => panic!("fail_fast mode should have returned an error"), - Err(e) => assert_eq!(e.err, ParseErrors::Lexer(LexerError::InvalidCharInt('g'))), + Err(e) => assert_eq!(*e.err, ParseErrors::Lexer(LexerError::InvalidCharInt('g'))), } } @@ -3560,7 +3560,7 @@ mod tests { ")".repeat(stack_limit + 1) ); - assert!(match parse(&exceeds_stack_depth_list).unwrap_err().err { + assert!(match *(parse(&exceeds_stack_depth_list).unwrap_err().err) { ParseErrors::ExpressionStackDepthTooDeep => true, x => panic!("expected a stack depth too deep error, got {x:?}"), }); @@ -3583,7 +3583,7 @@ mod tests { } ); - assert!(match parse(&exceeds_stack_depth_tuple).unwrap_err().err { + assert!(match *parse(&exceeds_stack_depth_tuple).unwrap_err().err { ParseErrors::ExpressionStackDepthTooDeep => true, x => panic!("expected a stack depth too deep error, got {x:?}"), }); diff --git a/clarity/src/vm/callables.rs b/clarity/src/vm/callables.rs index e7f9aa6a0ec..bceb74b8787 100644 --- a/clarity/src/vm/callables.rs +++ b/clarity/src/vm/callables.rs @@ -228,8 +228,8 @@ impl DefinedFunction { _ => { if !type_sig.admits(env.epoch(), value)? { return Err(CheckErrors::TypeValueError( - type_sig.clone(), - value.clone(), + Box::new(type_sig.clone()), + Box::new(value.clone()), ) .into()); } @@ -272,9 +272,11 @@ impl DefinedFunction { } _ => { if !type_sig.admits(env.epoch(), &cast_value)? { - return Err( - CheckErrors::TypeValueError(type_sig.clone(), cast_value).into() - ); + return Err(CheckErrors::TypeValueError( + Box::new(type_sig.clone()), + Box::new(cast_value), + ) + .into()); } } } @@ -447,9 +449,11 @@ fn clarity2_implicit_cast(type_sig: &TypeSignature, value: &Value) -> Result ty, None => { // This should be unreachable if the type-checker has already run successfully - return Err( - CheckErrors::TypeValueError(type_sig.clone(), value.clone()).into() - ); + return Err(CheckErrors::TypeValueError( + Box::new(type_sig.clone()), + Box::new(value.clone()), + ) + .into()); } }; cast_data_map.insert(name.clone(), clarity2_implicit_cast(to_type, field_value)?); diff --git a/clarity/src/vm/clarity.rs b/clarity/src/vm/clarity.rs index 17ba96f0eae..1f4505d7a44 100644 --- a/clarity/src/vm/clarity.rs +++ b/clarity/src/vm/clarity.rs @@ -23,9 +23,9 @@ pub enum Error { AbortedByCallback { /// What the output value of the transaction would have been. /// This will be a Some for contract-calls, and None for contract initialization txs. - output: Option, + output: Option>, /// The asset map which was evaluated by the abort callback - assets_modified: AssetMap, + assets_modified: Box, /// The events from the transaction processing tx_events: Vec, /// A human-readable explanation for aborting the transaction @@ -65,7 +65,7 @@ impl std::error::Error for Error { impl From for Error { fn from(e: CheckError) -> Self { - match e.err { + match *e.err { CheckErrors::CostOverflow => { Error::CostError(ExecutionCost::max_value(), ExecutionCost::max_value()) } @@ -100,7 +100,7 @@ impl From for Error { impl From for Error { fn from(e: ParseError) -> Self { - match e.err { + match *e.err { ParseErrors::CostOverflow => { Error::CostError(ExecutionCost::max_value(), ExecutionCost::max_value()) } @@ -244,7 +244,7 @@ pub trait TransactionConnection: ClarityConnection { let cost_track = contract_analysis.take_contract_cost_tracker(); (cost_track, Ok((contract_ast, contract_analysis))) } - Err((e, cost_track)) => (cost_track, Err(e.into())), + Err(e) => (e.1, Err(e.0.into())), } }) } @@ -347,8 +347,8 @@ pub trait TransactionConnection: ClarityConnection { .and_then(|(value, assets_modified, tx_events, reason)| { if let Some(reason) = reason { Err(Error::AbortedByCallback { - output: Some(value), - assets_modified, + output: Some(Box::new(value)), + assets_modified: Box::new(assets_modified), tx_events, reason, }) @@ -399,7 +399,7 @@ pub trait TransactionConnection: ClarityConnection { if let Some(reason) = reason { Err(Error::AbortedByCallback { output: None, - assets_modified, + assets_modified: Box::new(assets_modified), tx_events, reason, }) diff --git a/clarity/src/vm/contexts.rs b/clarity/src/vm/contexts.rs index 4974c95c51b..b15e1acf11b 100644 --- a/clarity/src/vm/contexts.rs +++ b/clarity/src/vm/contexts.rs @@ -1134,7 +1134,11 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> { self.epoch(), &expected_type, value.clone(), - ).ok_or_else(|| CheckErrors::TypeValueError(expected_type, value.clone()))?; + ).ok_or_else(|| CheckErrors::TypeValueError( + Box::new(expected_type), + Box::new(value.clone()), + ) + )?; Ok(sanitized_value) }) @@ -1762,10 +1766,10 @@ impl<'a, 'hooks> GlobalContext<'a, 'hooks> { self.commit()?; Ok(result) } else { - Err( - CheckErrors::PublicFunctionMustReturnResponse(TypeSignature::type_of(&result)?) - .into(), - ) + Err(CheckErrors::PublicFunctionMustReturnResponse(Box::new( + TypeSignature::type_of(&result)?, + )) + .into()) } } else { self.roll_back()?; diff --git a/clarity/src/vm/database/clarity_db.rs b/clarity/src/vm/database/clarity_db.rs index 55b15ab75aa..70f9f7172dd 100644 --- a/clarity/src/vm/database/clarity_db.rs +++ b/clarity/src/vm/database/clarity_db.rs @@ -1515,9 +1515,11 @@ impl ClarityDatabase<'_> { .value_type .admits(&self.get_clarity_epoch_version()?, &value)? { - return Err( - CheckErrors::TypeValueError(variable_descriptor.value_type.clone(), value).into(), - ); + return Err(CheckErrors::TypeValueError( + Box::new(variable_descriptor.value_type.clone()), + Box::new(value), + ) + .into()); } let key = ClarityDatabase::make_key_for_trip( @@ -1673,8 +1675,8 @@ impl ClarityDatabase<'_> { .admits(&self.get_clarity_epoch_version()?, key_value)? { return Err(CheckErrors::TypeValueError( - map_descriptor.key_type.clone(), - (*key_value).clone(), + Box::new(map_descriptor.key_type.clone()), + Box::new(key_value.clone()), ) .into()); } @@ -1704,8 +1706,8 @@ impl ClarityDatabase<'_> { .admits(&self.get_clarity_epoch_version()?, key_value)? { return Err(CheckErrors::TypeValueError( - map_descriptor.key_type.clone(), - (*key_value).clone(), + Box::new(map_descriptor.key_type.clone()), + Box::new(key_value.clone()), ) .into()); } @@ -1846,17 +1848,21 @@ impl ClarityDatabase<'_> { .key_type .admits(&self.get_clarity_epoch_version()?, &key_value)? { - return Err( - CheckErrors::TypeValueError(map_descriptor.key_type.clone(), key_value).into(), - ); + return Err(CheckErrors::TypeValueError( + Box::new(map_descriptor.key_type.clone()), + Box::new(key_value), + ) + .into()); } if !map_descriptor .value_type .admits(&self.get_clarity_epoch_version()?, &value)? { - return Err( - CheckErrors::TypeValueError(map_descriptor.value_type.clone(), value).into(), - ); + return Err(CheckErrors::TypeValueError( + Box::new(map_descriptor.value_type.clone()), + Box::new(value), + ) + .into()); } let key_serialized = key_value.serialize_to_hex()?; @@ -1902,8 +1908,8 @@ impl ClarityDatabase<'_> { .admits(&self.get_clarity_epoch_version()?, key_value)? { return Err(CheckErrors::TypeValueError( - map_descriptor.key_type.clone(), - (*key_value).clone(), + Box::new(map_descriptor.key_type.clone()), + Box::new(key_value.clone()), ) .into()); } @@ -2119,7 +2125,11 @@ impl ClarityDatabase<'_> { key_type: &TypeSignature, ) -> Result { if !key_type.admits(&self.get_clarity_epoch_version()?, asset)? { - return Err(CheckErrors::TypeValueError(key_type.clone(), (*asset).clone()).into()); + return Err(CheckErrors::TypeValueError( + Box::new(key_type.clone()), + Box::new(asset.clone()), + ) + .into()); } let key = ClarityDatabase::make_key_for_quad( @@ -2168,7 +2178,11 @@ impl ClarityDatabase<'_> { epoch: &StacksEpochId, ) -> Result<()> { if !key_type.admits(&self.get_clarity_epoch_version()?, asset)? { - return Err(CheckErrors::TypeValueError(key_type.clone(), (*asset).clone()).into()); + return Err(CheckErrors::TypeValueError( + Box::new(key_type.clone()), + Box::new(asset.clone()), + ) + .into()); } let key = ClarityDatabase::make_key_for_quad( @@ -2193,7 +2207,11 @@ impl ClarityDatabase<'_> { epoch: &StacksEpochId, ) -> Result<()> { if !key_type.admits(&self.get_clarity_epoch_version()?, asset)? { - return Err(CheckErrors::TypeValueError(key_type.clone(), (*asset).clone()).into()); + return Err(CheckErrors::TypeValueError( + Box::new(key_type.clone()), + Box::new(asset.clone()), + ) + .into()); } let key = ClarityDatabase::make_key_for_quad( diff --git a/clarity/src/vm/functions/arithmetic.rs b/clarity/src/vm/functions/arithmetic.rs index a04e813786a..2d5c2aff3ae 100644 --- a/clarity/src/vm/functions/arithmetic.rs +++ b/clarity/src/vm/functions/arithmetic.rs @@ -78,7 +78,7 @@ macro_rules! type_force_binary_arithmetic { (Value::UInt(x), Value::UInt(y)) => U128Ops::$function(x, y), (x, _) => Err(CheckErrors::UnionTypeValueError( vec![TypeSignature::IntType, TypeSignature::UIntType], - x, + Box::new(x), ) .into()), } @@ -93,7 +93,7 @@ macro_rules! type_force_binary_comparison_v1 { (Value::UInt(x), Value::UInt(y)) => U128Ops::$function(x, y), (x, _) => Err(CheckErrors::UnionTypeValueError( vec![TypeSignature::IntType, TypeSignature::UIntType], - x, + Box::new(x), ) .into()), } @@ -127,7 +127,7 @@ macro_rules! type_force_binary_comparison_v2 { TypeSignature::max_string_utf8()?, TypeSignature::max_buffer()?, ], - x, + Box::new(x), ) .into()), } @@ -141,7 +141,7 @@ macro_rules! type_force_unary_arithmetic { Value::UInt(x) => U128Ops::$function(x), x => Err(CheckErrors::UnionTypeValueError( vec![TypeSignature::IntType, TypeSignature::UIntType], - x, + Box::new(x), ) .into()), } @@ -163,8 +163,8 @@ macro_rules! type_force_variadic_arithmetic { .map(|x| match x { Value::Int(value) => Ok(value), _ => Err(CheckErrors::TypeValueError( - TypeSignature::IntType, - x.clone(), + Box::new(TypeSignature::IntType), + Box::new(x.clone()), )), }) .collect(); @@ -177,8 +177,8 @@ macro_rules! type_force_variadic_arithmetic { .map(|x| match x { Value::UInt(value) => Ok(value), _ => Err(CheckErrors::TypeValueError( - TypeSignature::UIntType, - x.clone(), + Box::new(TypeSignature::UIntType), + Box::new(x.clone()), )), }) .collect(); @@ -187,7 +187,7 @@ macro_rules! type_force_variadic_arithmetic { } _ => Err(CheckErrors::UnionTypeValueError( vec![TypeSignature::IntType, TypeSignature::UIntType], - first.clone(), + Box::new(first.clone()), ) .into()), } @@ -600,12 +600,12 @@ pub fn native_bitwise_left_shift(input: Value, pos: Value) -> InterpreterResult< } _ => Err(CheckErrors::UnionTypeError( vec![TypeSignature::IntType, TypeSignature::UIntType], - TypeSignature::type_of(&input)?, + Box::new(TypeSignature::type_of(&input)?), ) .into()), } } else { - Err(CheckErrors::TypeValueError(TypeSignature::UIntType, pos).into()) + Err(CheckErrors::TypeValueError(Box::new(TypeSignature::UIntType), Box::new(pos)).into()) } } @@ -626,12 +626,12 @@ pub fn native_bitwise_right_shift(input: Value, pos: Value) -> InterpreterResult } _ => Err(CheckErrors::UnionTypeError( vec![TypeSignature::IntType, TypeSignature::UIntType], - TypeSignature::type_of(&input)?, + Box::new(TypeSignature::type_of(&input)?), ) .into()), } } else { - Err(CheckErrors::TypeValueError(TypeSignature::UIntType, pos).into()) + Err(CheckErrors::TypeValueError(Box::new(TypeSignature::UIntType), Box::new(pos)).into()) } } @@ -641,7 +641,7 @@ pub fn native_to_uint(input: Value) -> InterpreterResult { u128::try_from(int_val).map_err(|_| RuntimeErrorType::ArithmeticUnderflow)?; Ok(Value::UInt(uint_val)) } else { - Err(CheckErrors::TypeValueError(TypeSignature::IntType, input).into()) + Err(CheckErrors::TypeValueError(Box::new(TypeSignature::IntType), Box::new(input)).into()) } } @@ -650,6 +650,6 @@ pub fn native_to_int(input: Value) -> InterpreterResult { let int_val = i128::try_from(uint_val).map_err(|_| RuntimeErrorType::ArithmeticOverflow)?; Ok(Value::Int(int_val)) } else { - Err(CheckErrors::TypeValueError(TypeSignature::UIntType, input).into()) + Err(CheckErrors::TypeValueError(Box::new(TypeSignature::UIntType), Box::new(input)).into()) } } diff --git a/clarity/src/vm/functions/assets.rs b/clarity/src/vm/functions/assets.rs index 1d60bc7a75a..62763fa3fc0 100644 --- a/clarity/src/vm/functions/assets.rs +++ b/clarity/src/vm/functions/assets.rs @@ -108,7 +108,10 @@ pub fn special_stx_balance( }; Ok(Value::UInt(balance)) } else { - Err(CheckErrors::TypeValueError(TypeSignature::PrincipalType, owner).into()) + Err( + CheckErrors::TypeValueError(Box::new(TypeSignature::PrincipalType), Box::new(owner)) + .into(), + ) } } @@ -222,7 +225,11 @@ pub fn special_stx_account( let principal = if let Value::Principal(p) = owner { p } else { - return Err(CheckErrors::TypeValueError(TypeSignature::PrincipalType, owner).into()); + return Err(CheckErrors::TypeValueError( + Box::new(TypeSignature::PrincipalType), + Box::new(owner), + ) + .into()); }; let stx_balance = env @@ -397,7 +404,11 @@ pub fn special_mint_asset_v200( )?; if !expected_asset_type.admits(env.epoch(), &asset)? { - return Err(CheckErrors::TypeValueError(expected_asset_type.clone(), asset).into()); + return Err(CheckErrors::TypeValueError( + Box::new(expected_asset_type.clone()), + Box::new(asset), + ) + .into()); } if let Value::Principal(ref to_principal) = to { @@ -433,7 +444,10 @@ pub fn special_mint_asset_v200( Ok(Value::okay_true()) } else { - Err(CheckErrors::TypeValueError(TypeSignature::PrincipalType, to).into()) + Err( + CheckErrors::TypeValueError(Box::new(TypeSignature::PrincipalType), Box::new(to)) + .into(), + ) } } @@ -464,7 +478,11 @@ pub fn special_mint_asset_v205( runtime_cost(ClarityCostFunction::NftMint, env, asset_size)?; if !expected_asset_type.admits(env.epoch(), &asset)? { - return Err(CheckErrors::TypeValueError(expected_asset_type.clone(), asset).into()); + return Err(CheckErrors::TypeValueError( + Box::new(expected_asset_type.clone()), + Box::new(asset), + ) + .into()); } if let Value::Principal(ref to_principal) = to { @@ -500,7 +518,10 @@ pub fn special_mint_asset_v205( Ok(Value::okay_true()) } else { - Err(CheckErrors::TypeValueError(TypeSignature::PrincipalType, to).into()) + Err( + CheckErrors::TypeValueError(Box::new(TypeSignature::PrincipalType), Box::new(to)) + .into(), + ) } } @@ -531,7 +552,11 @@ pub fn special_transfer_asset_v200( )?; if !expected_asset_type.admits(env.epoch(), &asset)? { - return Err(CheckErrors::TypeValueError(expected_asset_type.clone(), asset).into()); + return Err(CheckErrors::TypeValueError( + Box::new(expected_asset_type.clone()), + Box::new(asset), + ) + .into()); } if let (Value::Principal(ref from_principal), Value::Principal(ref to_principal)) = (from, to) { @@ -621,7 +646,11 @@ pub fn special_transfer_asset_v205( runtime_cost(ClarityCostFunction::NftTransfer, env, asset_size)?; if !expected_asset_type.admits(env.epoch(), &asset)? { - return Err(CheckErrors::TypeValueError(expected_asset_type.clone(), asset).into()); + return Err(CheckErrors::TypeValueError( + Box::new(expected_asset_type.clone()), + Box::new(asset), + ) + .into()); } if let (Value::Principal(ref from_principal), Value::Principal(ref to_principal)) = (from, to) { @@ -812,7 +841,10 @@ pub fn special_get_balance( )?; Ok(Value::UInt(balance)) } else { - Err(CheckErrors::TypeValueError(TypeSignature::PrincipalType, owner).into()) + Err( + CheckErrors::TypeValueError(Box::new(TypeSignature::PrincipalType), Box::new(owner)) + .into(), + ) } } @@ -841,7 +873,11 @@ pub fn special_get_owner_v200( )?; if !expected_asset_type.admits(env.epoch(), &asset)? { - return Err(CheckErrors::TypeValueError(expected_asset_type.clone(), asset).into()); + return Err(CheckErrors::TypeValueError( + Box::new(expected_asset_type.clone()), + Box::new(asset), + ) + .into()); } match env.global_context.database.get_nft_owner( @@ -884,7 +920,11 @@ pub fn special_get_owner_v205( runtime_cost(ClarityCostFunction::NftOwner, env, asset_size)?; if !expected_asset_type.admits(env.epoch(), &asset)? { - return Err(CheckErrors::TypeValueError(expected_asset_type.clone(), asset).into()); + return Err(CheckErrors::TypeValueError( + Box::new(expected_asset_type.clone()), + Box::new(asset), + ) + .into()); } match env.global_context.database.get_nft_owner( @@ -1014,7 +1054,11 @@ pub fn special_burn_asset_v200( )?; if !expected_asset_type.admits(env.epoch(), &asset)? { - return Err(CheckErrors::TypeValueError(expected_asset_type.clone(), asset).into()); + return Err(CheckErrors::TypeValueError( + Box::new(expected_asset_type.clone()), + Box::new(asset), + ) + .into()); } if let Value::Principal(ref sender_principal) = sender { @@ -1062,7 +1106,10 @@ pub fn special_burn_asset_v200( Ok(Value::okay_true()) } else { - Err(CheckErrors::TypeValueError(TypeSignature::PrincipalType, sender).into()) + Err( + CheckErrors::TypeValueError(Box::new(TypeSignature::PrincipalType), Box::new(sender)) + .into(), + ) } } @@ -1095,7 +1142,11 @@ pub fn special_burn_asset_v205( runtime_cost(ClarityCostFunction::NftBurn, env, asset_size)?; if !expected_asset_type.admits(env.epoch(), &asset)? { - return Err(CheckErrors::TypeValueError(expected_asset_type.clone(), asset).into()); + return Err(CheckErrors::TypeValueError( + Box::new(expected_asset_type.clone()), + Box::new(asset), + ) + .into()); } if let Value::Principal(ref sender_principal) = sender { @@ -1143,6 +1194,9 @@ pub fn special_burn_asset_v205( Ok(Value::okay_true()) } else { - Err(CheckErrors::TypeValueError(TypeSignature::PrincipalType, sender).into()) + Err( + CheckErrors::TypeValueError(Box::new(TypeSignature::PrincipalType), Box::new(sender)) + .into(), + ) } } diff --git a/clarity/src/vm/functions/boolean.rs b/clarity/src/vm/functions/boolean.rs index 08716cfe64c..e692b4ad71c 100644 --- a/clarity/src/vm/functions/boolean.rs +++ b/clarity/src/vm/functions/boolean.rs @@ -25,7 +25,11 @@ use crate::vm::types::{TypeSignature, Value}; fn type_force_bool(value: &Value) -> Result { match *value { Value::Bool(boolean) => Ok(boolean), - _ => Err(CheckErrors::TypeValueError(TypeSignature::BoolType, value.clone()).into()), + _ => Err(CheckErrors::TypeValueError( + Box::new(TypeSignature::BoolType), + Box::new(value.clone()), + ) + .into()), } } diff --git a/clarity/src/vm/functions/conversions.rs b/clarity/src/vm/functions/conversions.rs index b922f13fc08..d2dca3f9353 100644 --- a/clarity/src/vm/functions/conversions.rs +++ b/clarity/src/vm/functions/conversions.rs @@ -57,10 +57,11 @@ pub fn buff_to_int_generic( .map_err(|_| InterpreterError::Expect("Failed to construct".into()))? { Err(CheckErrors::TypeValueError( - SequenceType(BufferType(BufferLength::try_from(16_u32).map_err( - |_| InterpreterError::Expect("Failed to construct".into()), - )?)), - value, + Box::new(SequenceType(BufferType( + BufferLength::try_from(16_u32) + .map_err(|_| InterpreterError::Expect("Failed to construct".into()))?, + ))), + Box::new(value), ) .into()) } else { @@ -82,10 +83,11 @@ pub fn buff_to_int_generic( } } _ => Err(CheckErrors::TypeValueError( - SequenceType(BufferType(BufferLength::try_from(16_u32).map_err( - |_| InterpreterError::Expect("Failed to construct".into()), - )?)), - value, + Box::new(SequenceType(BufferType( + BufferLength::try_from(16_u32) + .map_err(|_| InterpreterError::Expect("Failed to construct".into()))?, + ))), + Box::new(value), ) .into()), } @@ -151,7 +153,7 @@ pub fn native_string_to_int_generic( TypeSignature::max_string_ascii()?, TypeSignature::max_string_utf8()?, ], - value, + Box::new(value), ) .into()), } @@ -204,7 +206,7 @@ pub fn native_int_to_string_generic( } _ => Err(CheckErrors::UnionTypeValueError( vec![TypeSignature::IntType, TypeSignature::UIntType], - value, + Box::new(value), ) .into()), } @@ -259,8 +261,8 @@ pub fn from_consensus_buff( Ok(buff_data.data) } else { Err(CheckErrors::TypeValueError( - TypeSignature::max_buffer()?, - value, + Box::new(TypeSignature::max_buffer()?), + Box::new(value), )) }?; diff --git a/clarity/src/vm/functions/crypto.rs b/clarity/src/vm/functions/crypto.rs index 1dd92a8f8fb..3b5223bd721 100644 --- a/clarity/src/vm/functions/crypto.rs +++ b/clarity/src/vm/functions/crypto.rs @@ -43,7 +43,7 @@ macro_rules! native_hash_func { TypeSignature::UIntType, TypeSignature::max_buffer()?, ], - input, + Box::new(input), )), }?; let hash = <$module>::from_data(&bytes); @@ -102,11 +102,19 @@ pub fn special_principal_of( let pub_key = match param0 { Value::Sequence(SequenceData::Buffer(BuffData { ref data })) => { if data.len() != 33 { - return Err(CheckErrors::TypeValueError(BUFF_33.clone(), param0).into()); + return Err(CheckErrors::TypeValueError( + Box::new(BUFF_33.clone()), + Box::new(param0), + ) + .into()); } data } - _ => return Err(CheckErrors::TypeValueError(BUFF_33.clone(), param0).into()), + _ => { + return Err( + CheckErrors::TypeValueError(Box::new(BUFF_33.clone()), Box::new(param0)).into(), + ) + } }; if let Ok(pub_key) = Secp256k1PublicKey::from_slice(pub_key) { @@ -140,25 +148,41 @@ pub fn special_secp256k1_recover( let message = match param0 { Value::Sequence(SequenceData::Buffer(BuffData { ref data })) => { if data.len() != 32 { - return Err(CheckErrors::TypeValueError(BUFF_32.clone(), param0).into()); + return Err(CheckErrors::TypeValueError( + Box::new(BUFF_32.clone()), + Box::new(param0), + ) + .into()); } data } - _ => return Err(CheckErrors::TypeValueError(BUFF_32.clone(), param0).into()), + _ => { + return Err( + CheckErrors::TypeValueError(Box::new(BUFF_32.clone()), Box::new(param0)).into(), + ) + } }; let param1 = eval(&args[1], env, context)?; let signature = match param1 { Value::Sequence(SequenceData::Buffer(BuffData { ref data })) => { if data.len() > 65 { - return Err(CheckErrors::TypeValueError(BUFF_65.clone(), param1).into()); + return Err(CheckErrors::TypeValueError( + Box::new(BUFF_65.clone()), + Box::new(param1), + ) + .into()); } if data.len() < 65 || data[64] > 3 { return Ok(Value::err_uint(2)); } data } - _ => return Err(CheckErrors::TypeValueError(BUFF_65.clone(), param1).into()), + _ => { + return Err( + CheckErrors::TypeValueError(Box::new(BUFF_65.clone()), Box::new(param1)).into(), + ) + } }; match secp256k1_recover(message, signature).map_err(|_| CheckErrors::InvalidSecp65k1Signature) { @@ -186,18 +210,30 @@ pub fn special_secp256k1_verify( let message = match param0 { Value::Sequence(SequenceData::Buffer(BuffData { ref data })) => { if data.len() != 32 { - return Err(CheckErrors::TypeValueError(BUFF_32.clone(), param0).into()); + return Err(CheckErrors::TypeValueError( + Box::new(BUFF_32.clone()), + Box::new(param0), + ) + .into()); } data } - _ => return Err(CheckErrors::TypeValueError(BUFF_32.clone(), param0).into()), + _ => { + return Err( + CheckErrors::TypeValueError(Box::new(BUFF_32.clone()), Box::new(param0)).into(), + ) + } }; let param1 = eval(&args[1], env, context)?; let signature = match param1 { Value::Sequence(SequenceData::Buffer(BuffData { ref data })) => { if data.len() > 65 { - return Err(CheckErrors::TypeValueError(BUFF_65.clone(), param1).into()); + return Err(CheckErrors::TypeValueError( + Box::new(BUFF_65.clone()), + Box::new(param1), + ) + .into()); } if data.len() < 64 { return Ok(Value::Bool(false)); @@ -207,18 +243,30 @@ pub fn special_secp256k1_verify( } data } - _ => return Err(CheckErrors::TypeValueError(BUFF_65.clone(), param1).into()), + _ => { + return Err( + CheckErrors::TypeValueError(Box::new(BUFF_65.clone()), Box::new(param1)).into(), + ) + } }; let param2 = eval(&args[2], env, context)?; let pubkey = match param2 { Value::Sequence(SequenceData::Buffer(BuffData { ref data })) => { if data.len() != 33 { - return Err(CheckErrors::TypeValueError(BUFF_33.clone(), param2).into()); + return Err(CheckErrors::TypeValueError( + Box::new(BUFF_33.clone()), + Box::new(param2), + ) + .into()); } data } - _ => return Err(CheckErrors::TypeValueError(BUFF_33.clone(), param2).into()), + _ => { + return Err( + CheckErrors::TypeValueError(Box::new(BUFF_33.clone()), Box::new(param2)).into(), + ) + } }; Ok(Value::Bool( diff --git a/clarity/src/vm/functions/database.rs b/clarity/src/vm/functions/database.rs index 4d0f880c650..a23d85619cf 100644 --- a/clarity/src/vm/functions/database.rs +++ b/clarity/src/vm/functions/database.rs @@ -210,9 +210,11 @@ pub fn special_contract_call( if let Some(returns_type_signature) = type_returns_constraint { let actual_returns = TypeSignature::type_of(&result)?; if !returns_type_signature.admits_type(env.epoch(), &actual_returns)? { - return Err( - CheckErrors::ReturnTypesMustMatch(returns_type_signature, actual_returns).into(), - ); + return Err(CheckErrors::ReturnTypesMustMatch( + Box::new(returns_type_signature), + Box::new(actual_returns), + ) + .into()); } } @@ -449,7 +451,9 @@ pub fn special_at_block( StacksBlockId::from(data.as_slice()) } } - x => return Err(CheckErrors::TypeValueError(BUFF_32.clone(), x).into()), + x => { + return Err(CheckErrors::TypeValueError(Box::new(BUFF_32.clone()), Box::new(x)).into()) + } }; env.add_memory(cost_constants::AT_BLOCK_MEMORY)?; @@ -755,7 +759,10 @@ pub fn special_get_block_info( let height_eval = eval(&args[1], env, context)?; let height_value = match height_eval { Value::UInt(result) => Ok(result), - x => Err(CheckErrors::TypeValueError(TypeSignature::UIntType, x)), + x => Err(CheckErrors::TypeValueError( + Box::new(TypeSignature::UIntType), + Box::new(x), + )), }?; let height_value = match u32::try_from(height_value) { @@ -903,7 +910,11 @@ pub fn special_get_burn_block_info( let height_value = match height_eval { Value::UInt(result) => result, x => { - return Err(CheckErrors::TypeValueError(TypeSignature::UIntType, x).into()); + return Err(CheckErrors::TypeValueError( + Box::new(TypeSignature::UIntType), + Box::new(x), + ) + .into()); } }; @@ -1000,7 +1011,10 @@ pub fn special_get_stacks_block_info( let height_eval = eval(&args[1], env, context)?; let height_value = match height_eval { Value::UInt(result) => Ok(result), - x => Err(CheckErrors::TypeValueError(TypeSignature::UIntType, x)), + x => Err(CheckErrors::TypeValueError( + Box::new(TypeSignature::UIntType), + Box::new(x), + )), }?; let Ok(height_value) = u32::try_from(height_value) else { @@ -1078,7 +1092,10 @@ pub fn special_get_tenure_info( let height_eval = eval(&args[1], env, context)?; let height_value = match height_eval { Value::UInt(result) => Ok(result), - x => Err(CheckErrors::TypeValueError(TypeSignature::UIntType, x)), + x => Err(CheckErrors::TypeValueError( + Box::new(TypeSignature::UIntType), + Box::new(x), + )), }?; let Ok(height_value) = u32::try_from(height_value) else { diff --git a/clarity/src/vm/functions/define.rs b/clarity/src/vm/functions/define.rs index 35e7981b3d5..8cdd9d8112f 100644 --- a/clarity/src/vm/functions/define.rs +++ b/clarity/src/vm/functions/define.rs @@ -211,7 +211,11 @@ fn handle_define_fungible_token( Some(total_supply_int), )) } else { - Err(CheckErrors::TypeValueError(TypeSignature::UIntType, total_supply_value).into()) + Err(CheckErrors::TypeValueError( + Box::new(TypeSignature::UIntType), + Box::new(total_supply_value), + ) + .into()) } } else { Ok(DefineResult::FungibleToken(asset_name.clone(), None)) diff --git a/clarity/src/vm/functions/mod.rs b/clarity/src/vm/functions/mod.rs index 7c92d9a9292..743f3b09c00 100644 --- a/clarity/src/vm/functions/mod.rs +++ b/clarity/src/vm/functions/mod.rs @@ -634,7 +634,11 @@ fn special_if( eval(&args[2], env, context) } } - _ => Err(CheckErrors::TypeValueError(TypeSignature::BoolType, conditional).into()), + _ => Err(CheckErrors::TypeValueError( + Box::new(TypeSignature::BoolType), + Box::new(conditional), + ) + .into()), } } @@ -655,10 +659,14 @@ fn special_asserts( Ok(conditional) } else { let thrown = eval(&args[1], env, context)?; - Err(ShortReturnType::AssertionFailed(thrown).into()) + Err(ShortReturnType::AssertionFailed(Box::new(thrown)).into()) } } - _ => Err(CheckErrors::TypeValueError(TypeSignature::BoolType, conditional).into()), + _ => Err(CheckErrors::TypeValueError( + Box::new(TypeSignature::BoolType), + Box::new(conditional), + ) + .into()), } } diff --git a/clarity/src/vm/functions/options.rs b/clarity/src/vm/functions/options.rs index edbd2d99081..c47dae91ccd 100644 --- a/clarity/src/vm/functions/options.rs +++ b/clarity/src/vm/functions/options.rs @@ -35,7 +35,7 @@ fn inner_unwrap(to_unwrap: Value) -> Result> { None } } - _ => return Err(CheckErrors::ExpectedOptionalOrResponseValue(to_unwrap).into()), + _ => return Err(CheckErrors::ExpectedOptionalOrResponseValue(Box::new(to_unwrap)).into()), }; Ok(result) @@ -50,7 +50,7 @@ fn inner_unwrap_err(to_unwrap: Value) -> Result> { None } } - _ => return Err(CheckErrors::ExpectedResponseValue(to_unwrap).into()), + _ => return Err(CheckErrors::ExpectedResponseValue(Box::new(to_unwrap)).into()), }; Ok(result) @@ -66,7 +66,7 @@ pub fn native_unwrap(input: Value) -> Result { pub fn native_unwrap_or_ret(input: Value, thrown: Value) -> Result { inner_unwrap(input).and_then(|opt_value| match opt_value { Some(v) => Ok(v), - None => Err(ShortReturnType::ExpectedValue(thrown).into()), + None => Err(ShortReturnType::ExpectedValue(Box::new(thrown)).into()), }) } @@ -80,7 +80,7 @@ pub fn native_unwrap_err(input: Value) -> Result { pub fn native_unwrap_err_or_ret(input: Value, thrown: Value) -> Result { inner_unwrap_err(input).and_then(|opt_value| match opt_value { Some(v) => Ok(v), - None => Err(ShortReturnType::ExpectedValue(thrown).into()), + None => Err(ShortReturnType::ExpectedValue(Box::new(thrown)).into()), }) } @@ -88,7 +88,7 @@ pub fn native_try_ret(input: Value) -> Result { match input { Value::Optional(data) => match data.data { Some(data) => Ok(*data), - None => Err(ShortReturnType::ExpectedValue(Value::none()).into()), + None => Err(ShortReturnType::ExpectedValue(Box::new(Value::none())).into()), }, Value::Response(data) => { if data.committed { @@ -99,10 +99,10 @@ pub fn native_try_ret(input: Value) -> Result { "BUG: Failed to construct new response type from old response type".into(), ) })?; - Err(ShortReturnType::ExpectedValue(short_return_val).into()) + Err(ShortReturnType::ExpectedValue(Box::new(short_return_val)).into()) } } - _ => Err(CheckErrors::ExpectedOptionalOrResponseValue(input).into()), + _ => Err(CheckErrors::ExpectedOptionalOrResponseValue(Box::new(input)).into()), } } @@ -212,7 +212,7 @@ pub fn special_match( match input { Value::Response(data) => special_match_resp(data, &args[1..], env, context), Value::Optional(data) => special_match_opt(data, &args[1..], env, context), - _ => Err(CheckErrors::BadMatchInput(TypeSignature::type_of(&input)?).into()), + _ => Err(CheckErrors::BadMatchInput(Box::new(TypeSignature::type_of(&input)?)).into()), } } @@ -223,14 +223,14 @@ pub fn native_some(input: Value) -> Result { fn is_some(input: Value) -> Result { match input { Value::Optional(ref data) => Ok(data.data.is_some()), - _ => Err(CheckErrors::ExpectedOptionalValue(input).into()), + _ => Err(CheckErrors::ExpectedOptionalValue(Box::new(input)).into()), } } fn is_okay(input: Value) -> Result { match input { Value::Response(data) => Ok(data.committed), - _ => Err(CheckErrors::ExpectedResponseValue(input).into()), + _ => Err(CheckErrors::ExpectedResponseValue(Box::new(input)).into()), } } @@ -264,6 +264,6 @@ pub fn native_default_to(default: Value, input: Value) -> Result { Some(data) => Ok(*data), None => Ok(default), }, - _ => Err(CheckErrors::ExpectedOptionalValue(input).into()), + _ => Err(CheckErrors::ExpectedOptionalValue(Box::new(input)).into()), } } diff --git a/clarity/src/vm/functions/principals.rs b/clarity/src/vm/functions/principals.rs index c3600e6654a..51fc33136f2 100644 --- a/clarity/src/vm/functions/principals.rs +++ b/clarity/src/vm/functions/principals.rs @@ -61,7 +61,11 @@ pub fn special_is_standard( let version = if let Value::Principal(ref p) = owner { p.version() } else { - return Err(CheckErrors::TypeValueError(TypeSignature::PrincipalType, owner).into()); + return Err(CheckErrors::TypeValueError( + Box::new(TypeSignature::PrincipalType), + Box::new(owner), + ) + .into()); }; Ok(Value::Bool(version_matches_current_network( @@ -165,7 +169,11 @@ pub fn special_principal_destruct( (issuer.0, issuer.1, Some(name)) } _ => { - return Err(CheckErrors::TypeValueError(TypeSignature::PrincipalType, principal).into()) + return Err(CheckErrors::TypeValueError( + Box::new(TypeSignature::PrincipalType), + Box::new(principal), + ) + .into()); } }; @@ -203,14 +211,16 @@ pub fn special_principal_construct( _ => { return { // This is an aborting error because this should have been caught in analysis pass. - Err(CheckErrors::TypeValueError(BUFF_1.clone(), version).into()) + Err(CheckErrors::TypeValueError(Box::new(BUFF_1.clone()), Box::new(version)).into()) }; } }; let version_byte = if verified_version.len() > 1 { // should have been caught by the type-checker - return Err(CheckErrors::TypeValueError(BUFF_1.clone(), version).into()); + return Err( + CheckErrors::TypeValueError(Box::new(BUFF_1.clone()), Box::new(version)).into(), + ); } else if verified_version.is_empty() { // the type checker does not check the actual length of the buffer, but a 0-length buffer // will type-check to (buff 1) @@ -233,13 +243,21 @@ pub fn special_principal_construct( // This is an aborting error because this should have been caught in analysis pass. let verified_hash_bytes = match hash_bytes { Value::Sequence(SequenceData::Buffer(BuffData { ref data })) => data, - _ => return Err(CheckErrors::TypeValueError(BUFF_20.clone(), hash_bytes).into()), + _ => { + return Err(CheckErrors::TypeValueError( + Box::new(BUFF_20.clone()), + Box::new(hash_bytes), + ) + .into()) + } }; // This must have been a (buff 20). // This is an aborting error because this should have been caught in analysis pass. if verified_hash_bytes.len() > 20 { - return Err(CheckErrors::TypeValueError(BUFF_20.clone(), hash_bytes).into()); + return Err( + CheckErrors::TypeValueError(Box::new(BUFF_20.clone()), Box::new(hash_bytes)).into(), + ); } // If the hash-bytes buffer has less than 20 bytes, this is a runtime error, because it @@ -260,8 +278,8 @@ pub fn special_principal_construct( Value::Sequence(SequenceData::String(CharType::ASCII(ascii_data))) => ascii_data, _ => { return Err(CheckErrors::TypeValueError( - TypeSignature::contract_name_string_ascii_type()?, - name, + Box::new(TypeSignature::contract_name_string_ascii_type()?), + Box::new(name), ) .into()) } @@ -277,8 +295,8 @@ pub fn special_principal_construct( // if it's too long, then this should have been caught by the type-checker if name_bytes.data.len() > CONTRACT_MAX_NAME_LENGTH { return Err(CheckErrors::TypeValueError( - TypeSignature::contract_name_string_ascii_type()?, - Value::from(name_bytes), + Box::new(TypeSignature::contract_name_string_ascii_type()?), + Box::new(Value::from(name_bytes)), ) .into()); } diff --git a/clarity/src/vm/functions/sequences.rs b/clarity/src/vm/functions/sequences.rs index 8bc89e7373f..cafc795d362 100644 --- a/clarity/src/vm/functions/sequences.rs +++ b/clarity/src/vm/functions/sequences.rs @@ -70,11 +70,18 @@ pub fn special_filter( if let Value::Bool(include) = filter_eval { Ok(include) } else { - Err(CheckErrors::TypeValueError(BoolType, filter_eval).into()) + Err( + CheckErrors::TypeValueError(Box::new(BoolType), Box::new(filter_eval)) + .into(), + ) } })?; } - _ => return Err(CheckErrors::ExpectedSequence(TypeSignature::type_of(&sequence)?).into()), + _ => { + return Err( + CheckErrors::ExpectedSequence(Box::new(TypeSignature::type_of(&sequence)?)).into(), + ) + } }; Ok(sequence) } @@ -106,7 +113,9 @@ pub fn special_fold( context, ) }), - _ => Err(CheckErrors::ExpectedSequence(TypeSignature::type_of(&sequence)?).into()), + _ => { + Err(CheckErrors::ExpectedSequence(Box::new(TypeSignature::type_of(&sequence)?)).into()) + } } } @@ -145,7 +154,8 @@ pub fn special_map( } _ => { return Err( - CheckErrors::ExpectedSequence(TypeSignature::type_of(&sequence)?).into(), + CheckErrors::ExpectedSequence(Box::new(TypeSignature::type_of(&sequence)?)) + .into(), ) } } @@ -209,7 +219,7 @@ pub fn special_append( data, }))) } else { - Err(CheckErrors::TypeValueError(entry_type, element).into()) + Err(CheckErrors::TypeValueError(Box::new(entry_type), Box::new(element)).into()) } } _ => Err(CheckErrors::ExpectedListApplication.into()), @@ -289,7 +299,8 @@ pub fn special_as_max_len( Value::Sequence(ref sequence_data) => sequence_data.len() as u128, _ => { return Err( - CheckErrors::ExpectedSequence(TypeSignature::type_of(&sequence)?).into(), + CheckErrors::ExpectedSequence(Box::new(TypeSignature::type_of(&sequence)?)) + .into(), ) } }; @@ -304,8 +315,8 @@ pub fn special_as_max_len( } else { let actual_len = eval(&args[1], env, context)?; Err(CheckErrors::TypeError( - TypeSignature::UIntType, - TypeSignature::type_of(&actual_len)?, + Box::new(TypeSignature::UIntType), + Box::new(TypeSignature::type_of(&actual_len)?), ) .into()) } @@ -314,7 +325,9 @@ pub fn special_as_max_len( pub fn native_len(sequence: Value) -> Result { match sequence { Value::Sequence(sequence_data) => Ok(Value::UInt(sequence_data.len() as u128)), - _ => Err(CheckErrors::ExpectedSequence(TypeSignature::type_of(&sequence)?).into()), + _ => { + Err(CheckErrors::ExpectedSequence(Box::new(TypeSignature::type_of(&sequence)?)).into()) + } } } @@ -325,7 +338,7 @@ pub fn native_index_of(sequence: Value, to_find: Value) -> Result { None => Ok(Value::none()), } } else { - Err(CheckErrors::ExpectedSequence(TypeSignature::type_of(&sequence)?).into()) + Err(CheckErrors::ExpectedSequence(Box::new(TypeSignature::type_of(&sequence)?)).into()) } } @@ -333,7 +346,9 @@ pub fn native_element_at(sequence: Value, index: Value) -> Result { let sequence_data = if let Value::Sequence(sequence_data) = sequence { sequence_data } else { - return Err(CheckErrors::ExpectedSequence(TypeSignature::type_of(&sequence)?).into()); + return Err( + CheckErrors::ExpectedSequence(Box::new(TypeSignature::type_of(&sequence)?)).into(), + ); }; let index = if let Value::UInt(index_u128) = index { @@ -343,7 +358,11 @@ pub fn native_element_at(sequence: Value, index: Value) -> Result { return Ok(Value::none()); } } else { - return Err(CheckErrors::TypeValueError(TypeSignature::UIntType, index).into()); + return Err(CheckErrors::TypeValueError( + Box::new(TypeSignature::UIntType), + Box::new(index), + ) + .into()); }; if let Some(result) = sequence_data.element_at(index)? { @@ -420,7 +439,7 @@ pub fn special_replace_at( let expected_elem_type = if let TypeSignature::SequenceType(seq_subtype) = &seq_type { seq_subtype.unit_type()? } else { - return Err(CheckErrors::ExpectedSequence(seq_type).into()); + return Err(CheckErrors::ExpectedSequence(Box::new(seq_type)).into()); }; let index_val = eval(&args[1], env, context)?; let new_element = eval(&args[2], env, context)?; @@ -428,7 +447,11 @@ pub fn special_replace_at( if expected_elem_type != TypeSignature::NoType && !expected_elem_type.admits(env.epoch(), &new_element)? { - return Err(CheckErrors::TypeValueError(expected_elem_type, new_element).into()); + return Err(CheckErrors::TypeValueError( + Box::new(expected_elem_type), + Box::new(new_element), + ) + .into()); } let index = if let Value::UInt(index_u128) = index_val { @@ -438,7 +461,11 @@ pub fn special_replace_at( return Ok(Value::none()); } } else { - return Err(CheckErrors::TypeValueError(TypeSignature::UIntType, index_val).into()); + return Err(CheckErrors::TypeValueError( + Box::new(TypeSignature::UIntType), + Box::new(index_val), + ) + .into()); }; if let Value::Sequence(data) = seq { @@ -448,6 +475,6 @@ pub fn special_replace_at( } data.replace_at(env.epoch(), index, new_element) } else { - Err(CheckErrors::ExpectedSequence(seq_type).into()) + Err(CheckErrors::ExpectedSequence(Box::new(seq_type)).into()) } } diff --git a/clarity/src/vm/functions/tuples.rs b/clarity/src/vm/functions/tuples.rs index 44519f13206..8d108ec6c3b 100644 --- a/clarity/src/vm/functions/tuples.rs +++ b/clarity/src/vm/functions/tuples.rs @@ -65,7 +65,10 @@ pub fn tuple_get( ) })?) } else { - Err(CheckErrors::ExpectedTuple(TypeSignature::type_of(&data)?).into()) + Err( + CheckErrors::ExpectedTuple(Box::new(TypeSignature::type_of(&data)?)) + .into(), + ) } } None => Ok(Value::none()), // just pass through none-types. @@ -75,19 +78,23 @@ pub fn tuple_get( runtime_cost(ClarityCostFunction::TupleGet, env, tuple_data.len())?; tuple_data.get_owned(arg_name) } - _ => Err(CheckErrors::ExpectedTuple(TypeSignature::type_of(&value)?).into()), + _ => Err(CheckErrors::ExpectedTuple(Box::new(TypeSignature::type_of(&value)?)).into()), } } pub fn tuple_merge(base: Value, update: Value) -> Result { let initial_values = match base { Value::Tuple(initial_values) => Ok(initial_values), - _ => Err(CheckErrors::ExpectedTuple(TypeSignature::type_of(&base)?)), + _ => Err(CheckErrors::ExpectedTuple(Box::new( + TypeSignature::type_of(&base)?, + ))), }?; let new_values = match update { Value::Tuple(new_values) => Ok(new_values), - _ => Err(CheckErrors::ExpectedTuple(TypeSignature::type_of(&update)?)), + _ => Err(CheckErrors::ExpectedTuple(Box::new( + TypeSignature::type_of(&update)?, + ))), }?; let combined = TupleData::shallow_merge(initial_values, new_values)?; diff --git a/clarity/src/vm/mod.rs b/clarity/src/vm/mod.rs index 22c2b04618c..7b27d63df4b 100644 --- a/clarity/src/vm/mod.rs +++ b/clarity/src/vm/mod.rs @@ -13,8 +13,6 @@ // // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#![allow(clippy::result_large_err)] - pub mod diagnostic; pub mod errors; diff --git a/clarity/src/vm/tests/contracts.rs b/clarity/src/vm/tests/contracts.rs index 229f09c9239..96e69fec16c 100644 --- a/clarity/src/vm/tests/contracts.rs +++ b/clarity/src/vm/tests/contracts.rs @@ -112,8 +112,16 @@ fn test_get_block_info_eval( Ok(Value::none()), Ok(Value::none()), Ok(Value::none()), - Err(CheckErrors::TypeValueError(TypeSignature::UIntType, Value::Int(-1)).into()), - Err(CheckErrors::TypeValueError(TypeSignature::UIntType, Value::Bool(true)).into()), + Err(CheckErrors::TypeValueError( + Box::new(TypeSignature::UIntType), + Box::new(Value::Int(-1)), + ) + .into()), + Err(CheckErrors::TypeValueError( + Box::new(TypeSignature::UIntType), + Box::new(Value::Bool(true)), + ) + .into()), Ok(Value::none()), Ok(Value::none()), Ok(Value::none()), @@ -1041,7 +1049,10 @@ fn test_ast_stack_depth() { "; assert_eq!( vm_execute(program).unwrap_err(), - RuntimeErrorType::ASTError(ParseErrors::VaryExpressionStackDepthTooDeep.into()).into() + RuntimeErrorType::ASTError(Box::new( + ParseErrors::VaryExpressionStackDepthTooDeep.into(), + )) + .into() ); } diff --git a/clarity/src/vm/tests/datamaps.rs b/clarity/src/vm/tests/datamaps.rs index c36454c0a02..c9cff25aa19 100644 --- a/clarity/src/vm/tests/datamaps.rs +++ b/clarity/src/vm/tests/datamaps.rs @@ -296,7 +296,7 @@ fn test_set_response_variable() { "#; let contract_src = contract_src.to_string(); assert_eq!( - Err(ShortReturnType::ExpectedValue(Value::Int(5)).into()), + Err(ShortReturnType::ExpectedValue(Box::new(Value::Int(5))).into()), execute(&contract_src) ); } diff --git a/clarity/src/vm/tests/defines.rs b/clarity/src/vm/tests/defines.rs index 7dd8eb7e656..f0b0f19ff41 100644 --- a/clarity/src/vm/tests/defines.rs +++ b/clarity/src/vm/tests/defines.rs @@ -25,10 +25,7 @@ use crate::vm::errors::{CheckErrors, Error}; use crate::vm::tests::test_clarity_versions; #[cfg(test)] use crate::vm::{ - ast::{ - build_ast, - errors::{ParseError, ParseErrors}, - }, + ast::{build_ast, errors::ParseErrors}, errors::RuntimeErrorType, types::{QualifiedContractIdentifier, TypeSignature, TypeSignatureExt as _, Value}, {execute, ClarityVersion}, @@ -73,8 +70,8 @@ fn test_accept_options(#[case] version: ClarityVersion, #[case] epoch: StacksEpo Ok(Some(Value::Int(0))), Ok(Some(Value::Int(10))), Err(CheckErrors::TypeValueError( - TypeSignature::from_string("(optional int)", version, epoch), - Value::some(Value::Bool(true)).unwrap(), + Box::new(TypeSignature::from_string("(optional int)", version, epoch)), + Box::new(Value::some(Value::Bool(true)).unwrap()), ) .into()), ]; @@ -132,11 +129,11 @@ fn test_unwrap_ret() { execute(test1).unwrap_err(), ); assert_eq_err( - CheckErrors::ExpectedOptionalOrResponseValue(Value::Int(1)), + CheckErrors::ExpectedOptionalOrResponseValue(Box::new(Value::Int(1))), execute(test2).unwrap_err(), ); assert_eq_err( - CheckErrors::ExpectedResponseValue(Value::Int(1)), + CheckErrors::ExpectedResponseValue(Box::new(Value::Int(1))), execute(test3).unwrap_err(), ); assert_eq!(Ok(Some(Value::Int(1))), execute(test4)); @@ -209,7 +206,7 @@ fn test_recursive_panic(#[case] version: ClarityVersion, #[case] epoch: StacksEp epoch, ) .unwrap_err(); - assert!(matches!(err.err, ParseErrors::CircularReference(_))); + assert!(matches!(*err.err, ParseErrors::CircularReference(_))); } #[test] @@ -476,37 +473,19 @@ fn test_define_trait_arg_count() { // These errors are hit in the trait resolver, before reaching the type-checker match execute(test0).unwrap_err() { - Error::Runtime( - RuntimeErrorType::ASTError(ParseError { - err: ParseErrors::DefineTraitBadSignature, - pre_expressions: _, - diagnostic: _, - }), - _, - ) => (), + Error::Runtime(RuntimeErrorType::ASTError(parse_err), _) + if *parse_err.err == ParseErrors::DefineTraitBadSignature => {} e => panic!("{e:?}"), }; match execute(test1).unwrap_err() { - Error::Runtime( - RuntimeErrorType::ASTError(ParseError { - err: ParseErrors::DefineTraitBadSignature, - pre_expressions: _, - diagnostic: _, - }), - _, - ) => (), + Error::Runtime(RuntimeErrorType::ASTError(parse_err), _) + if *parse_err.err == ParseErrors::DefineTraitBadSignature => {} e => panic!("{e}"), }; execute(test2).unwrap(); match execute(test3).unwrap_err() { - Error::Runtime( - RuntimeErrorType::ASTError(ParseError { - err: ParseErrors::DefineTraitBadSignature, - pre_expressions: _, - diagnostic: _, - }), - _, - ) => (), + Error::Runtime(RuntimeErrorType::ASTError(parse_err), _) + if *parse_err.err == ParseErrors::DefineTraitBadSignature => {} e => panic!("{e}"), }; } @@ -520,37 +499,19 @@ fn test_use_trait_arg_count() { // These errors are hit in the trait resolver, before reaching the type-checker match execute(test0).unwrap_err() { - Error::Runtime( - RuntimeErrorType::ASTError(ParseError { - err: ParseErrors::ImportTraitBadSignature, - pre_expressions: _, - diagnostic: _, - }), - _, - ) => (), + Error::Runtime(RuntimeErrorType::ASTError(parse_err), _) + if *parse_err.err == ParseErrors::ImportTraitBadSignature => {} e => panic!("{e:?}"), }; match execute(test1).unwrap_err() { - Error::Runtime( - RuntimeErrorType::ASTError(ParseError { - err: ParseErrors::ImportTraitBadSignature, - pre_expressions: _, - diagnostic: _, - }), - _, - ) => (), + Error::Runtime(RuntimeErrorType::ASTError(parse_err), _) + if *parse_err.err == ParseErrors::ImportTraitBadSignature => {} e => panic!("{e}"), }; execute(test2).unwrap(); match execute(test3).unwrap_err() { - Error::Runtime( - RuntimeErrorType::ASTError(ParseError { - err: ParseErrors::ImportTraitBadSignature, - pre_expressions: _, - diagnostic: _, - }), - _, - ) => (), + Error::Runtime(RuntimeErrorType::ASTError(parse_err), _) + if *parse_err.err == ParseErrors::ImportTraitBadSignature => {} e => panic!("{e}"), }; } @@ -563,26 +524,14 @@ fn test_impl_trait_arg_count() { // These errors are hit in the trait resolver, before reaching the type-checker match execute(test0).unwrap_err() { - Error::Runtime( - RuntimeErrorType::ASTError(ParseError { - err: ParseErrors::ImplTraitBadSignature, - pre_expressions: _, - diagnostic: _, - }), - _, - ) => (), + Error::Runtime(RuntimeErrorType::ASTError(parse_err), _) + if *parse_err.err == ParseErrors::ImplTraitBadSignature => {} e => panic!("{e:?}"), }; execute(test1).unwrap(); match execute(test2).unwrap_err() { - Error::Runtime( - RuntimeErrorType::ASTError(ParseError { - err: ParseErrors::ImplTraitBadSignature, - pre_expressions: _, - diagnostic: _, - }), - _, - ) => (), + Error::Runtime(RuntimeErrorType::ASTError(parse_err), _) + if *parse_err.err == ParseErrors::ImplTraitBadSignature => {} e => panic!("{e}"), }; } diff --git a/clarity/src/vm/tests/principals.rs b/clarity/src/vm/tests/principals.rs index aec00b3173d..aefbd2cc7a3 100644 --- a/clarity/src/vm/tests/principals.rs +++ b/clarity/src/vm/tests/principals.rs @@ -27,7 +27,7 @@ fn test_simple_is_standard_check_inputs() { true ) .unwrap_err(), - CheckErrors::TypeValueError(PrincipalType, Value::UInt(10)).into() + CheckErrors::TypeValueError(Box::new(PrincipalType), Box::new(Value::UInt(10)),).into() ); } @@ -952,10 +952,10 @@ fn test_principal_construct_check_errors() { let input = r#"(principal-construct? 0x590493 0x0102030405060708091011121314151617181920)"#; assert_eq!( Err(CheckErrors::TypeValueError( - BUFF_1.clone(), - Value::Sequence(SequenceData::Buffer(BuffData { + Box::new(BUFF_1.clone()), + Box::new(Value::Sequence(SequenceData::Buffer(BuffData { data: hex_bytes("590493").unwrap() - })) + }))), ) .into()), execute_with_parameters( @@ -971,7 +971,10 @@ fn test_principal_construct_check_errors() { // `CheckErrors`. let input = r#"(principal-construct? u22 0x0102030405060708091011121314151617181920)"#; assert_eq!( - Err(CheckErrors::TypeValueError(BUFF_1.clone(), Value::UInt(22)).into()), + Err( + CheckErrors::TypeValueError(Box::new(BUFF_1.clone()), Box::new(Value::UInt(22)),) + .into() + ), execute_with_parameters( input, ClarityVersion::Clarity2, @@ -994,10 +997,10 @@ fn test_principal_construct_check_errors() { ) .unwrap_err(), CheckErrors::TypeValueError( - BUFF_20.clone(), - Value::Sequence(SequenceData::Buffer(BuffData { + Box::new(BUFF_20.clone()), + Box::new(Value::Sequence(SequenceData::Buffer(BuffData { data: hex_bytes("010203040506070809101112131415161718192021").unwrap() - })) + }))), ) .into() ); @@ -1006,12 +1009,14 @@ fn test_principal_construct_check_errors() { let input = r#"(principal-construct? 0x16 0x0102030405060708091011121314151617181920 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")"#; assert_eq!( Err(CheckErrors::TypeValueError( - TypeSignature::contract_name_string_ascii_type().unwrap(), - Value::Sequence(SequenceData::String(CharType::ASCII(ASCIIData { - data: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" - .as_bytes() - .to_vec() - }))) + Box::new(TypeSignature::contract_name_string_ascii_type().unwrap()), + Box::new(Value::Sequence(SequenceData::String(CharType::ASCII( + ASCIIData { + data: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + .as_bytes() + .to_vec() + } + )))) ) .into()), execute_with_parameters( diff --git a/clarity/src/vm/tests/sequences.rs b/clarity/src/vm/tests/sequences.rs index d89a2460b23..3ea779b7d67 100644 --- a/clarity/src/vm/tests/sequences.rs +++ b/clarity/src/vm/tests/sequences.rs @@ -112,18 +112,18 @@ fn test_index_of() { ]; let bad_expected = [ - CheckErrors::ExpectedSequence(TypeSignature::IntType), + CheckErrors::ExpectedSequence(Box::new(TypeSignature::IntType)), CheckErrors::TypeValueError( - TypeSignature::min_buffer().unwrap(), - execute("\"a\"").unwrap().unwrap(), + Box::new(TypeSignature::min_buffer().unwrap()), + Box::new(execute("\"a\"").unwrap().unwrap()), ), CheckErrors::TypeValueError( - TypeSignature::min_string_utf8().unwrap(), - execute("\"a\"").unwrap().unwrap(), + Box::new(TypeSignature::min_string_utf8().unwrap()), + Box::new(execute("\"a\"").unwrap().unwrap()), ), CheckErrors::TypeValueError( - TypeSignature::min_string_ascii().unwrap(), - execute("u\"a\"").unwrap().unwrap(), + Box::new(TypeSignature::min_string_ascii().unwrap()), + Box::new(execute("u\"a\"").unwrap().unwrap()), ), ]; @@ -173,8 +173,8 @@ fn test_element_at() { let bad = ["(element-at 3 u1)", "(element-at (list 1 2 3) 1)"]; let bad_expected = [ - CheckErrors::ExpectedSequence(TypeSignature::IntType), - CheckErrors::TypeValueError(TypeSignature::UIntType, Value::Int(1)), + CheckErrors::ExpectedSequence(Box::new(TypeSignature::IntType)), + CheckErrors::TypeValueError(Box::new(TypeSignature::UIntType), Box::new(Value::Int(1))), ]; for (bad_test, expected) in bad.iter().zip(bad_expected.iter()) { @@ -451,7 +451,7 @@ fn test_simple_map_append() { assert_eq!( execute("(append (append (list) 1) u2)").unwrap_err(), - CheckErrors::TypeValueError(IntType, Value::UInt(2)).into() + CheckErrors::TypeValueError(Box::new(IntType), Box::new(Value::UInt(2))).into() ); } @@ -587,7 +587,7 @@ fn test_simple_list_concat() { assert_eq!( execute("(concat (list 1) (list u4 u8))").unwrap_err(), - CheckErrors::TypeError(IntType, UIntType).into() + CheckErrors::TypeError(Box::new(IntType), Box::new(UIntType)).into() ); assert_eq!( @@ -710,25 +710,25 @@ fn test_simple_list_replace_at() { // The sequence input has the wrong type assert_eq!( execute_v2("(replace-at? 0 u0 (list 0))").unwrap_err(), - CheckErrors::ExpectedSequence(IntType).into() + CheckErrors::ExpectedSequence(Box::new(IntType)).into() ); // The type of the index should be uint. assert_eq!( execute_v2("(replace-at? (list 1) 0 0)").unwrap_err(), - CheckErrors::TypeValueError(UIntType, Value::Int(0)).into() + CheckErrors::TypeValueError(Box::new(UIntType), Box::new(Value::Int(0))).into() ); // The element input has the wrong type assert_eq!( execute_v2("(replace-at? (list 2 3) u0 true)").unwrap_err(), - CheckErrors::TypeValueError(IntType, Value::Bool(true)).into() + CheckErrors::TypeValueError(Box::new(IntType), Box::new(Value::Bool(true))).into() ); // The element input has the wrong type assert_eq!( execute_v2("(replace-at? (list 2 3) u0 0x00)").unwrap_err(), - CheckErrors::TypeValueError(IntType, Value::buff_from_byte(0)).into() + CheckErrors::TypeValueError(Box::new(IntType), Box::new(Value::buff_from_byte(0))).into() ); } @@ -768,29 +768,32 @@ fn test_simple_buff_replace_at() { // The sequence input has the wrong type assert_eq!( execute_v2("(replace-at? 33 u0 0x00)").unwrap_err(), - CheckErrors::ExpectedSequence(IntType).into() + CheckErrors::ExpectedSequence(Box::new(IntType)).into() ); // The type of the index should be uint. assert_eq!( execute_v2("(replace-at? 0x002244 0 0x99)").unwrap_err(), - CheckErrors::TypeValueError(UIntType, Value::Int(0)).into() + CheckErrors::TypeValueError(Box::new(UIntType), Box::new(Value::Int(0))).into() ); // The element input has the wrong type let buff_len = BufferLength::try_from(1u32).unwrap(); assert_eq!( execute_v2("(replace-at? 0x445522 u0 55)").unwrap_err(), - CheckErrors::TypeValueError(SequenceType(BufferType(buff_len.clone())), Value::Int(55)) - .into() + CheckErrors::TypeValueError( + Box::new(SequenceType(BufferType(buff_len.clone()))), + Box::new(Value::Int(55)) + ) + .into() ); // The element input has the wrong type assert_eq!( execute_v2("(replace-at? 0x445522 u0 (list 5))").unwrap_err(), CheckErrors::TypeValueError( - SequenceType(BufferType(buff_len.clone())), - Value::list_from(vec![Value::Int(5)]).unwrap() + Box::new(SequenceType(BufferType(buff_len.clone()))), + Box::new(Value::list_from(vec![Value::Int(5)]).unwrap()) ) .into() ); @@ -799,8 +802,8 @@ fn test_simple_buff_replace_at() { assert_eq!( execute_v2("(replace-at? 0x445522 u0 0x0044)").unwrap_err(), CheckErrors::TypeValueError( - SequenceType(BufferType(buff_len)), - Value::buff_from(vec![0, 68]).unwrap() + Box::new(SequenceType(BufferType(buff_len))), + Box::new(Value::buff_from(vec![0, 68]).unwrap()) ) .into() ); @@ -842,13 +845,13 @@ fn test_simple_string_ascii_replace_at() { // The sequence input has the wrong type assert_eq!( execute_v2("(replace-at? 33 u0 \"c\")").unwrap_err(), - CheckErrors::ExpectedSequence(IntType).into() + CheckErrors::ExpectedSequence(Box::new(IntType)).into() ); // The type of the index should be uint. assert_eq!( execute_v2("(replace-at? \"abc\" 0 \"c\")").unwrap_err(), - CheckErrors::TypeValueError(UIntType, Value::Int(0)).into() + CheckErrors::TypeValueError(Box::new(UIntType), Box::new(Value::Int(0))).into() ); // The element input has the wrong type @@ -856,8 +859,8 @@ fn test_simple_string_ascii_replace_at() { assert_eq!( execute_v2("(replace-at? \"abc\" u0 55)").unwrap_err(), CheckErrors::TypeValueError( - SequenceType(StringType(ASCII(buff_len.clone()))), - Value::Int(55) + Box::new(SequenceType(StringType(ASCII(buff_len.clone())))), + Box::new(Value::Int(55)) ) .into() ); @@ -866,8 +869,8 @@ fn test_simple_string_ascii_replace_at() { assert_eq!( execute_v2("(replace-at? \"abc\" u0 0x00)").unwrap_err(), CheckErrors::TypeValueError( - SequenceType(StringType(ASCII(buff_len.clone()))), - Value::buff_from_byte(0) + Box::new(SequenceType(StringType(ASCII(buff_len.clone())))), + Box::new(Value::buff_from_byte(0)) ) .into() ); @@ -876,8 +879,8 @@ fn test_simple_string_ascii_replace_at() { assert_eq!( execute_v2("(replace-at? \"abc\" u0 \"de\")").unwrap_err(), CheckErrors::TypeValueError( - SequenceType(StringType(ASCII(buff_len))), - Value::string_ascii_from_bytes("de".into()).unwrap() + Box::new(SequenceType(StringType(ASCII(buff_len)))), + Box::new(Value::string_ascii_from_bytes("de".into()).unwrap()) ) .into() ); @@ -923,13 +926,13 @@ fn test_simple_string_utf8_replace_at() { // The sequence input has the wrong type assert_eq!( execute_v2("(replace-at? 33 u0 u\"c\")").unwrap_err(), - CheckErrors::ExpectedSequence(IntType).into() + CheckErrors::ExpectedSequence(Box::new(IntType)).into() ); // The type of the index should be uint. assert_eq!( execute_v2("(replace-at? u\"abc\" 0 u\"c\")").unwrap_err(), - CheckErrors::TypeValueError(UIntType, Value::Int(0)).into() + CheckErrors::TypeValueError(Box::new(UIntType), Box::new(Value::Int(0))).into() ); // The element input has the wrong type @@ -937,8 +940,10 @@ fn test_simple_string_utf8_replace_at() { assert_eq!( execute_v2("(replace-at? u\"abc\" u0 55)").unwrap_err(), CheckErrors::TypeValueError( - TypeSignature::SequenceType(StringType(StringSubtype::UTF8(str_len.clone()))), - Value::Int(55) + Box::new(TypeSignature::SequenceType(StringType( + StringSubtype::UTF8(str_len.clone()) + ))), + Box::new(Value::Int(55)) ) .into() ); @@ -947,8 +952,10 @@ fn test_simple_string_utf8_replace_at() { assert_eq!( execute_v2("(replace-at? u\"abc\" u0 0x00)").unwrap_err(), CheckErrors::TypeValueError( - TypeSignature::SequenceType(StringType(StringSubtype::UTF8(str_len.clone()))), - Value::buff_from_byte(0) + Box::new(TypeSignature::SequenceType(StringType( + StringSubtype::UTF8(str_len.clone()) + ))), + Box::new(Value::buff_from_byte(0)) ) .into() ); @@ -957,8 +964,10 @@ fn test_simple_string_utf8_replace_at() { assert_eq!( execute_v2("(replace-at? u\"abc\" u0 u\"de\")").unwrap_err(), CheckErrors::TypeValueError( - TypeSignature::SequenceType(StringType(StringSubtype::UTF8(str_len))), - Value::string_utf8_from_string_utf8_literal("de".to_string()).unwrap() + Box::new(TypeSignature::SequenceType(StringType( + StringSubtype::UTF8(str_len) + ))), + Box::new(Value::string_utf8_from_string_utf8_literal("de".to_string()).unwrap()) ) .into() ); @@ -989,19 +998,21 @@ fn test_simple_buff_assert_max_len() { assert_eq!( execute("(as-max-len? 0x313233 3)").unwrap_err(), - CheckErrors::TypeError(UIntType, IntType).into() + CheckErrors::TypeError(Box::new(UIntType), Box::new(IntType)).into() ); assert_eq!( execute("(as-max-len? 1 u3)").unwrap_err(), - CheckErrors::ExpectedSequence(IntType).into() + CheckErrors::ExpectedSequence(Box::new(IntType)).into() ); assert_eq!( execute("(as-max-len? 0x313233 0x31)").unwrap_err(), CheckErrors::TypeError( - UIntType, - SequenceType(SequenceSubtype::BufferType(1_u32.try_into().unwrap())) + Box::new(UIntType), + Box::new(SequenceType(SequenceSubtype::BufferType( + 1_u32.try_into().unwrap() + ))) ) .into() ); @@ -1164,14 +1175,14 @@ fn test_construct_bad_list(#[case] version: ClarityVersion, #[case] epoch: Stack let test1 = "(list 1 2 3 true)"; assert_eq!( execute(test1).unwrap_err(), - CheckErrors::TypeError(IntType, BoolType).into() + CheckErrors::TypeError(Box::new(IntType), Box::new(BoolType)).into() ); let test2 = "(define-private (bad-function (x int)) (if (is-eq x 1) true x)) (map bad-function (list 0 1 2 3))"; assert_eq!( execute(test2).unwrap_err(), - CheckErrors::TypeError(IntType, BoolType).into() + CheckErrors::TypeError(Box::new(IntType), Box::new(BoolType)).into() ); let bad_2d_list = "(list (list 1 2 3) (list true false true))"; @@ -1179,13 +1190,13 @@ fn test_construct_bad_list(#[case] version: ClarityVersion, #[case] epoch: Stack assert_eq!( execute(bad_2d_list).unwrap_err(), - CheckErrors::TypeError(IntType, BoolType).into() + CheckErrors::TypeError(Box::new(IntType), Box::new(BoolType)).into() ); assert_eq!( execute(bad_high_order_list).unwrap_err(), CheckErrors::TypeError( - IntType, - TypeSignature::from_string("(list 3 int)", version, epoch) + Box::new(IntType), + Box::new(TypeSignature::from_string("(list 3 int)", version, epoch)) ) .into() ); @@ -1211,6 +1222,6 @@ fn test_eval_func_arg_panic() { assert_eq!(e, execute(test4).unwrap_err()); let test5 = "(map + (list 1 2 3 4) 2)"; - let e: Error = CheckErrors::ExpectedSequence(IntType).into(); + let e: Error = CheckErrors::ExpectedSequence(Box::new(IntType)).into(); assert_eq!(e, execute(test5).unwrap_err()); } diff --git a/clarity/src/vm/tests/simple_apply_eval.rs b/clarity/src/vm/tests/simple_apply_eval.rs index c4ca5781198..53558e3548f 100644 --- a/clarity/src/vm/tests/simple_apply_eval.rs +++ b/clarity/src/vm/tests/simple_apply_eval.rs @@ -581,14 +581,14 @@ fn test_secp256k1_errors() { ]; let expectations: &[Error] = &[ - CheckErrors::TypeValueError(BUFF_32.clone(), Value::Sequence(SequenceData::Buffer(BuffData { data: hex_bytes("de5b9eb9e7c5592930eb2e30a01369c36586d872082ed8181ee83d2a0ec20f").unwrap() }))).into(), - CheckErrors::TypeValueError(BUFF_65.clone(), Value::Sequence(SequenceData::Buffer(BuffData { data: hex_bytes("8738487ebe69b93d8e51583be8eee50bb4213fc49c767d329632730cc193b873554428fc936ca3569afc15f1c9365f6591d6251a89fee9c9ac661116824d3a130100").unwrap() }))).into(), + CheckErrors::TypeValueError(Box::new(BUFF_32.clone()), Box::new(Value::Sequence(SequenceData::Buffer(BuffData { data: hex_bytes("de5b9eb9e7c5592930eb2e30a01369c36586d872082ed8181ee83d2a0ec20f").unwrap() })))).into(), + CheckErrors::TypeValueError(Box::new(BUFF_65.clone()), Box::new(Value::Sequence(SequenceData::Buffer(BuffData { data: hex_bytes("8738487ebe69b93d8e51583be8eee50bb4213fc49c767d329632730cc193b873554428fc936ca3569afc15f1c9365f6591d6251a89fee9c9ac661116824d3a130100").unwrap() })))).into(), CheckErrors::IncorrectArgumentCount(2, 1).into(), CheckErrors::IncorrectArgumentCount(2, 3).into(), - CheckErrors::TypeValueError(BUFF_32.clone(), Value::Sequence(SequenceData::Buffer(BuffData { data: hex_bytes("de5b9eb9e7c5592930eb2e30a01369c36586d872082ed8181ee83d2a0ec20f").unwrap() }))).into(), - CheckErrors::TypeValueError(BUFF_65.clone(), Value::Sequence(SequenceData::Buffer(BuffData { data: hex_bytes("8738487ebe69b93d8e51583be8eee50bb4213fc49c767d329632730cc193b873554428fc936ca3569afc15f1c9365f6591d6251a89fee9c9ac661116824d3a130111").unwrap() }))).into(), - CheckErrors::TypeValueError(BUFF_33.clone(), Value::Sequence(SequenceData::Buffer(BuffData { data: hex_bytes("03adb8de4bfb65db2cfd6120d55c6526ae9c52e675db7e47308636534ba7").unwrap() }))).into(), + CheckErrors::TypeValueError(Box::new(BUFF_32.clone()), Box::new(Value::Sequence(SequenceData::Buffer(BuffData { data: hex_bytes("de5b9eb9e7c5592930eb2e30a01369c36586d872082ed8181ee83d2a0ec20f").unwrap() })))).into(), + CheckErrors::TypeValueError(Box::new(BUFF_65.clone()), Box::new(Value::Sequence(SequenceData::Buffer(BuffData { data: hex_bytes("8738487ebe69b93d8e51583be8eee50bb4213fc49c767d329632730cc193b873554428fc936ca3569afc15f1c9365f6591d6251a89fee9c9ac661116824d3a130111").unwrap() })))).into(), + CheckErrors::TypeValueError(Box::new(BUFF_33.clone()), Box::new(Value::Sequence(SequenceData::Buffer(BuffData { data: hex_bytes("03adb8de4bfb65db2cfd6120d55c6526ae9c52e675db7e47308636534ba7").unwrap() })))).into(), CheckErrors::IncorrectArgumentCount(3, 2).into(), CheckErrors::IncorrectArgumentCount(1, 2).into(), @@ -880,30 +880,38 @@ fn test_sequence_comparisons_clarity1() { let error_expectations: &[Error] = &[ CheckErrors::UnionTypeValueError( vec![TypeSignature::IntType, TypeSignature::UIntType], - Value::Sequence(SequenceData::String(CharType::ASCII(ASCIIData { - data: "baa".as_bytes().to_vec(), - }))), + Box::new(Value::Sequence(SequenceData::String(CharType::ASCII( + ASCIIData { + data: "baa".as_bytes().to_vec(), + }, + )))), ) .into(), CheckErrors::UnionTypeValueError( vec![TypeSignature::IntType, TypeSignature::UIntType], - Value::Sequence(SequenceData::String(CharType::ASCII(ASCIIData { - data: "baa".as_bytes().to_vec(), - }))), + Box::new(Value::Sequence(SequenceData::String(CharType::ASCII( + ASCIIData { + data: "baa".as_bytes().to_vec(), + }, + )))), ) .into(), CheckErrors::UnionTypeValueError( vec![TypeSignature::IntType, TypeSignature::UIntType], - Value::Sequence(SequenceData::String(CharType::ASCII(ASCIIData { - data: "baa".as_bytes().to_vec(), - }))), + Box::new(Value::Sequence(SequenceData::String(CharType::ASCII( + ASCIIData { + data: "baa".as_bytes().to_vec(), + }, + )))), ) .into(), CheckErrors::UnionTypeValueError( vec![TypeSignature::IntType, TypeSignature::UIntType], - Value::Sequence(SequenceData::String(CharType::ASCII(ASCIIData { - data: "baa".as_bytes().to_vec(), - }))), + Box::new(Value::Sequence(SequenceData::String(CharType::ASCII( + ASCIIData { + data: "baa".as_bytes().to_vec(), + }, + )))), ) .into(), ]; @@ -983,12 +991,12 @@ fn test_sequence_comparisons_mismatched_types() { let v1_error_expectations: &[Error] = &[ CheckErrors::UnionTypeValueError( vec![TypeSignature::IntType, TypeSignature::UIntType], - Value::Int(0), + Box::new(Value::Int(0)), ) .into(), CheckErrors::UnionTypeValueError( vec![TypeSignature::IntType, TypeSignature::UIntType], - Value::Int(0), + Box::new(Value::Int(0)), ) .into(), ]; @@ -1010,7 +1018,7 @@ fn test_sequence_comparisons_mismatched_types() { TypeSignature::max_string_utf8().unwrap(), TypeSignature::max_buffer().unwrap(), ], - Value::Int(0), + Box::new(Value::Int(0)), ) .into(), CheckErrors::UnionTypeValueError( @@ -1021,7 +1029,7 @@ fn test_sequence_comparisons_mismatched_types() { TypeSignature::max_string_utf8().unwrap(), TypeSignature::max_buffer().unwrap(), ], - Value::Int(0), + Box::new(Value::Int(0)), ) .into(), ]; @@ -1044,9 +1052,11 @@ fn test_sequence_comparisons_mismatched_types() { TypeSignature::max_string_utf8().unwrap(), TypeSignature::max_buffer().unwrap(), ], - Value::Sequence(SequenceData::String(CharType::ASCII(ASCIIData { - data: "baa".as_bytes().to_vec(), - }))), + Box::new(Value::Sequence(SequenceData::String(CharType::ASCII( + ASCIIData { + data: "baa".as_bytes().to_vec(), + }, + )))), ) .into(), CheckErrors::UnionTypeValueError( @@ -1057,9 +1067,11 @@ fn test_sequence_comparisons_mismatched_types() { TypeSignature::max_string_utf8().unwrap(), TypeSignature::max_buffer().unwrap(), ], - Value::Sequence(SequenceData::String(CharType::ASCII(ASCIIData { - data: "baa".as_bytes().to_vec(), - }))), + Box::new(Value::Sequence(SequenceData::String(CharType::ASCII( + ASCIIData { + data: "baa".as_bytes().to_vec(), + }, + )))), ) .into(), ]; @@ -1102,7 +1114,11 @@ fn test_simple_arithmetic_errors(#[case] version: ClarityVersion, #[case] epoch: let expectations: &[Error] = &[ CheckErrors::IncorrectArgumentCount(2, 1).into(), - CheckErrors::TypeValueError(TypeSignature::IntType, Value::Bool(true)).into(), + CheckErrors::TypeValueError( + Box::new(TypeSignature::IntType), + Box::new(Value::Bool(true)), + ) + .into(), RuntimeErrorType::DivisionByZero.into(), RuntimeErrorType::DivisionByZero.into(), RuntimeErrorType::ArithmeticOverflow.into(), @@ -1129,8 +1145,8 @@ fn test_simple_arithmetic_errors(#[case] version: ClarityVersion, #[case] epoch: ) .into(), CheckErrors::TypeError( - TypeSignature::from_string("bool", version, epoch), - TypeSignature::from_string("int", version, epoch), + Box::new(TypeSignature::from_string("bool", version, epoch)), + Box::new(TypeSignature::from_string("int", version, epoch)), ) .into(), ]; @@ -1156,10 +1172,11 @@ fn test_unsigned_arithmetic() { RuntimeErrorType::ArithmeticUnderflow.into(), CheckErrors::UnionTypeValueError( vec![TypeSignature::IntType, TypeSignature::UIntType], - Value::UInt(10), + Box::new(Value::UInt(10)), ) .into(), - CheckErrors::TypeValueError(TypeSignature::UIntType, Value::Int(80)).into(), + CheckErrors::TypeValueError(Box::new(TypeSignature::UIntType), Box::new(Value::Int(80))) + .into(), RuntimeErrorType::ArithmeticUnderflow.into(), RuntimeErrorType::ArithmeticOverflow.into(), ]; @@ -1191,20 +1208,20 @@ fn test_options_errors() { let expectations: &[Error] = &[ CheckErrors::IncorrectArgumentCount(1, 2).into(), - CheckErrors::ExpectedOptionalValue(Value::Bool(true)).into(), + CheckErrors::ExpectedOptionalValue(Box::new(Value::Bool(true))).into(), CheckErrors::IncorrectArgumentCount(1, 2).into(), - CheckErrors::ExpectedResponseValue(Value::Bool(true)).into(), + CheckErrors::ExpectedResponseValue(Box::new(Value::Bool(true))).into(), CheckErrors::IncorrectArgumentCount(1, 2).into(), - CheckErrors::ExpectedResponseValue(Value::Bool(true)).into(), + CheckErrors::ExpectedResponseValue(Box::new(Value::Bool(true))).into(), CheckErrors::IncorrectArgumentCount(1, 2).into(), - CheckErrors::ExpectedOptionalValue(Value::Bool(true)).into(), + CheckErrors::ExpectedOptionalValue(Box::new(Value::Bool(true))).into(), CheckErrors::IncorrectArgumentCount(1, 2).into(), CheckErrors::IncorrectArgumentCount(1, 2).into(), CheckErrors::IncorrectArgumentCount(1, 2).into(), CheckErrors::IncorrectArgumentCount(2, 3).into(), - CheckErrors::ExpectedOptionalValue(Value::Bool(true)).into(), - CheckErrors::ExpectedTuple(TypeSignature::IntType).into(), - CheckErrors::ExpectedTuple(TypeSignature::IntType).into(), + CheckErrors::ExpectedOptionalValue(Box::new(Value::Bool(true))).into(), + CheckErrors::ExpectedTuple(Box::new(TypeSignature::IntType)).into(), + CheckErrors::ExpectedTuple(Box::new(TypeSignature::IntType)).into(), ]; for (program, expectation) in tests.iter().zip(expectations.iter()) { @@ -1409,9 +1426,12 @@ fn test_option_destructs() { let expectations: &[Result] = &[ Ok(Value::Int(1)), Ok(Value::Int(1)), - Err(CheckErrors::ExpectedResponseValue(Value::some(Value::Int(2)).unwrap()).into()), + Err( + CheckErrors::ExpectedResponseValue(Box::new(Value::some(Value::Int(2)).unwrap())) + .into(), + ), Ok(Value::Int(3)), - Err(ShortReturnType::ExpectedValue(Value::Int(2)).into()), + Err(ShortReturnType::ExpectedValue(Box::new(Value::Int(2))).into()), Ok(Value::Int(3)), Ok(Value::Int(3)), Ok(Value::Int(3)), @@ -1422,14 +1442,14 @@ fn test_option_destructs() { Ok(Value::Int(9)), Ok(Value::Int(2)), Ok(Value::Int(8)), - Err(CheckErrors::BadMatchInput(TypeSignature::IntType).into()), - Err(CheckErrors::BadMatchInput(TypeSignature::IntType).into()), - Err(ShortReturnType::ExpectedValue(Value::error(Value::UInt(1)).unwrap()).into()), + Err(CheckErrors::BadMatchInput(Box::new(TypeSignature::IntType)).into()), + Err(CheckErrors::BadMatchInput(Box::new(TypeSignature::IntType)).into()), + Err(ShortReturnType::ExpectedValue(Box::new(Value::error(Value::UInt(1)).unwrap())).into()), Ok(Value::Int(3)), - Err(ShortReturnType::ExpectedValue(Value::none()).into()), + Err(ShortReturnType::ExpectedValue(Box::new(Value::none())).into()), Ok(Value::Bool(true)), Err(CheckErrors::IncorrectArgumentCount(1, 2).into()), - Err(CheckErrors::ExpectedOptionalOrResponseValue(Value::Int(1)).into()), + Err(CheckErrors::ExpectedOptionalOrResponseValue(Box::new(Value::Int(1))).into()), ]; for (program, expectation) in tests.iter().zip(expectations.iter()) { @@ -1462,7 +1482,7 @@ fn test_hash_errors() { TypeSignature::UIntType, TypeSignature::max_buffer().unwrap(), ], - Value::Bool(true), + Box::new(Value::Bool(true)), ) .into(), CheckErrors::UnionTypeValueError( @@ -1471,7 +1491,7 @@ fn test_hash_errors() { TypeSignature::UIntType, TypeSignature::max_buffer().unwrap(), ], - Value::Bool(true), + Box::new(Value::Bool(true)), ) .into(), CheckErrors::UnionTypeValueError( @@ -1480,7 +1500,7 @@ fn test_hash_errors() { TypeSignature::UIntType, TypeSignature::max_buffer().unwrap(), ], - Value::Bool(true), + Box::new(Value::Bool(true)), ) .into(), CheckErrors::UnionTypeValueError( @@ -1489,7 +1509,7 @@ fn test_hash_errors() { TypeSignature::UIntType, TypeSignature::max_buffer().unwrap(), ], - Value::Bool(true), + Box::new(Value::Bool(true)), ) .into(), CheckErrors::IncorrectArgumentCount(1, 2).into(), @@ -1499,7 +1519,7 @@ fn test_hash_errors() { TypeSignature::UIntType, TypeSignature::max_buffer().unwrap(), ], - Value::Bool(true), + Box::new(Value::Bool(true)), ) .into(), CheckErrors::IncorrectArgumentCount(1, 2).into(), @@ -1655,12 +1675,12 @@ fn test_asserts_short_circuit() { ]; let expectations: &[Error] = &[ - Error::ShortReturn(ShortReturnType::AssertionFailed( + Error::ShortReturn(ShortReturnType::AssertionFailed(Box::new( Value::error(Value::Int(0)).unwrap(), - )), - Error::ShortReturn(ShortReturnType::AssertionFailed( + ))), + Error::ShortReturn(ShortReturnType::AssertionFailed(Box::new( Value::error(Value::Int(1)).unwrap(), - )), + ))), ]; tests diff --git a/clarity/src/vm/tests/variables.rs b/clarity/src/vm/tests/variables.rs index c3652d97f0c..e4e64b2e7b3 100644 --- a/clarity/src/vm/tests/variables.rs +++ b/clarity/src/vm/tests/variables.rs @@ -55,7 +55,7 @@ fn test_block_height( let err = analysis.unwrap_err(); assert_eq!( CheckErrors::UndefinedVariable("block-height".to_string()), - err.err + *err.err ); } else { assert!(analysis.is_ok()); @@ -113,7 +113,7 @@ fn test_stacks_block_height( let err = analysis.unwrap_err(); assert_eq!( CheckErrors::UndefinedVariable("stacks-block-height".to_string()), - err.err + *err.err ); } else { assert!(analysis.is_ok()); @@ -173,7 +173,7 @@ fn test_tenure_height( let err = analysis.unwrap_err(); assert_eq!( CheckErrors::UndefinedVariable("tenure-height".to_string()), - err.err + *err.err ); } else { assert!(analysis.is_ok()); @@ -246,7 +246,7 @@ fn expect_contract_error( for (when, err_condition, expected_error) in expected_errors { if *when == WhenError::Analysis && err_condition(version, epoch) { let err = analysis.unwrap_err(); - assert_eq!(*expected_error, err.err); + assert_eq!(*expected_error, *err.err); // Do not continue with the test if the analysis failed. return; diff --git a/clarity/src/vm/tooling/mod.rs b/clarity/src/vm/tooling/mod.rs index 0713d4576f0..5dbff058da4 100644 --- a/clarity/src/vm/tooling/mod.rs +++ b/clarity/src/vm/tooling/mod.rs @@ -50,6 +50,6 @@ pub fn mem_type_check( .cloned(); Ok((first_type, x)) } - Err((e, _)) => Err(e), + Err(e) => Err(e.0), } } diff --git a/pox-locking/src/lib.rs b/pox-locking/src/lib.rs index 8336ee64b66..16c11c8af26 100644 --- a/pox-locking/src/lib.rs +++ b/pox-locking/src/lib.rs @@ -24,8 +24,6 @@ //! checks if the function called requires applying or updating the //! `STXBalance` struct's locks, and if the function was successfully //! invoked. If so, it updates the PoX lock. -#![allow(clippy::result_large_err)] - use clarity::boot_util::boot_code_id; use clarity::vm::contexts::GlobalContext; use clarity::vm::errors::{Error as ClarityError, RuntimeErrorType}; diff --git a/stacks-signer/src/lib.rs b/stacks-signer/src/lib.rs index c1de71e0594..ae6bfc47ecd 100644 --- a/stacks-signer/src/lib.rs +++ b/stacks-signer/src/lib.rs @@ -1,5 +1,4 @@ #![forbid(missing_docs)] -#![allow(clippy::result_large_err)] /*! # stacks-signer: a library for creating a Stacks compliant signer. A default implementation binary is also provided. Usage documentation can be found in the [README](https://github.com/Trust-Machines/core-eng/stacks-signer-api/README.md). diff --git a/stackslib/src/chainstate/stacks/boot/contract_tests.rs b/stackslib/src/chainstate/stacks/boot/contract_tests.rs index 900a560eac6..01ef881b858 100644 --- a/stackslib/src/chainstate/stacks/boot/contract_tests.rs +++ b/stackslib/src/chainstate/stacks/boot/contract_tests.rs @@ -1722,7 +1722,7 @@ fn simple_epoch21_test() { .expect_err("2.0 'bad' contract should not deploy successfully") { ClarityError::Analysis(e) => { - assert_eq!(e.err, CheckErrors::UnknownFunction("stx-account".into())); + assert_eq!(*e.err, CheckErrors::UnknownFunction("stx-account".into())); } e => panic!("Should have caused an analysis error: {:#?}", e), }; diff --git a/stackslib/src/chainstate/stacks/db/transactions.rs b/stackslib/src/chainstate/stacks/db/transactions.rs index 2df237e8fac..4d1027320a2 100644 --- a/stackslib/src/chainstate/stacks/db/transactions.rs +++ b/stackslib/src/chainstate/stacks/db/transactions.rs @@ -402,8 +402,8 @@ pub fn handle_clarity_runtime_error(error: clarity_error) -> ClarityRuntimeTxErr tx_events, reason, } => ClarityRuntimeTxError::AbortedByCallback { - output, - assets_modified, + output: output.map(|v| *v), + assets_modified: *assets_modified, tx_events, reason, }, @@ -1251,7 +1251,7 @@ impl StacksChainState { // invalidates the block, since this should have prevented the // block from getting relayed in the first place if let clarity_error::Parse(ref parse_error) = &other_error { - match parse_error.err { + match *parse_error.err { ParseErrors::ExpressionStackDepthTooDeep | ParseErrors::VaryExpressionStackDepthTooDeep => { info!("Transaction {} is problematic and should have prevented this block from being relayed", tx.txid()); diff --git a/stackslib/src/chainstate/stacks/miner.rs b/stackslib/src/chainstate/stacks/miner.rs index 8000fa2d3e8..254eecb95ec 100644 --- a/stackslib/src/chainstate/stacks/miner.rs +++ b/stackslib/src/chainstate/stacks/miner.rs @@ -646,7 +646,7 @@ impl TransactionResult { ClarityRuntimeTxError::Acceptable { error, .. } => { if let clarity_error::Parse(ref parse_err) = error { info!("Parse error: {}", parse_err; "txid" => %tx.txid()); - match &parse_err.err { + match *parse_err.err { ParseErrors::ExpressionStackDepthTooDeep | ParseErrors::VaryExpressionStackDepthTooDeep => { info!("Problematic transaction failed AST depth check"; "txid" => %tx.txid()); @@ -678,8 +678,8 @@ impl TransactionResult { tx_events, reason, } => Error::ClarityError(clarity_error::AbortedByCallback { - output, - assets_modified, + output: output.map(Box::new), + assets_modified: Box::new(assets_modified), tx_events, reason, }), diff --git a/stackslib/src/clarity_cli.rs b/stackslib/src/clarity_cli.rs index 6b714771b26..1ae8f648de6 100644 --- a/stackslib/src/clarity_cli.rs +++ b/stackslib/src/clarity_cli.rs @@ -158,7 +158,7 @@ fn parse( DEFAULT_CLI_EPOCH, ASTRules::PrecheckSize, ) - .map_err(RuntimeErrorType::ASTError)?; + .map_err(|e| RuntimeErrorType::ASTError(Box::new(e)))?; Ok(ast.expressions) } @@ -204,7 +204,7 @@ fn run_analysis_free( expressions: &mut [SymbolicExpression], marf_kv: &mut C, save_contract: bool, -) -> Result { +) -> Result> { let clarity_version = ClarityVersion::default_for_epoch(DEFAULT_CLI_EPOCH); analysis::run_analysis( contract_identifier, @@ -225,7 +225,7 @@ fn run_analysis( header_db: &CLIHeadersDB, marf_kv: &mut C, save_contract: bool, -) -> Result { +) -> Result> { let mainnet = header_db.is_mainnet(); let clarity_version = ClarityVersion::default_for_epoch(DEFAULT_CLI_EPOCH); let cost_track = LimitedCostTracker::new( @@ -1207,12 +1207,13 @@ pub fn invoke_command(invoked_by: &str, args: &[String]) -> (i32, Option contract_analysis, - Err((e, cost_tracker)) => { + Err(boxed) => { + let (e, cost_tracker) = *boxed; let mut result = json!({ "message": "Checks failed.", "error": { "analysis": serde_json::to_value(&e.diagnostic).unwrap(), - } + }, }); add_costs(&mut result, costs, cost_tracker.get_total()); return (1, Some(result)); @@ -1285,7 +1286,8 @@ pub fn invoke_command(invoked_by: &str, args: &[String]) -> (i32, Option (), - Err((error, _)) => { + Err(boxed) => { + let (error, _) = *boxed; println!("Type check error:\n{}", error); continue; } @@ -1354,14 +1356,17 @@ pub fn invoke_command(invoked_by: &str, args: &[String]) -> (i32, Option ( - 1, - Some(json!({ - "error": { - "analysis": serde_json::to_value(&format!("{}", error)).unwrap() - } - })), - ), + Err(boxed) => { + let (error, _) = *boxed; + ( + 1, + Some(json!({ + "error": { + "analysis": serde_json::to_value(&format!("{}", error)).unwrap() + } + })), + ) + } } } "eval" => { @@ -1697,7 +1702,8 @@ pub fn invoke_command(invoked_by: &str, args: &[String]) -> (i32, Option { + Err(boxed) => { + let (error, cost_tracker) = *boxed; let mut result = json!({ "error": { "initialization": serde_json::to_value(&format!("{}", error)).unwrap() diff --git a/stackslib/src/clarity_vm/clarity.rs b/stackslib/src/clarity_vm/clarity.rs index 6ef509bdc32..22b0bcd145c 100644 --- a/stackslib/src/clarity_vm/clarity.rs +++ b/stackslib/src/clarity_vm/clarity.rs @@ -2738,7 +2738,7 @@ mod tests { panic!("Expects a AbortedByCallback error") }; - assert_eq!(result_value, Value::okay(Value::Int(10)).unwrap()); + assert_eq!(*result_value, Value::okay(Value::Int(10)).unwrap()); // prior transaction should have rolled back due to abort call back! assert_eq!( diff --git a/stackslib/src/clarity_vm/tests/contracts.rs b/stackslib/src/clarity_vm/tests/contracts.rs index 0b8af83c408..27a9023e46f 100644 --- a/stackslib/src/clarity_vm/tests/contracts.rs +++ b/stackslib/src/clarity_vm/tests/contracts.rs @@ -54,7 +54,7 @@ fn test_get_burn_block_info_eval() { ASTRules::PrecheckSize, ); if let Err(ClarityError::Analysis(check_error)) = res { - if let CheckErrors::UnknownFunction(func_name) = check_error.err { + if let CheckErrors::UnknownFunction(func_name) = *check_error.err { assert_eq!(func_name, "get-burn-block-info?"); } else { panic!("Bad analysis error: {:?}", &check_error); @@ -79,7 +79,7 @@ fn test_get_burn_block_info_eval() { ASTRules::PrecheckSize, ); if let Err(ClarityError::Analysis(check_error)) = res { - if let CheckErrors::UnknownFunction(func_name) = check_error.err { + if let CheckErrors::UnknownFunction(func_name) = *check_error.err { assert_eq!(func_name, "get-burn-block-info?"); } else { panic!("Bad analysis error: {:?}", &check_error); @@ -180,7 +180,7 @@ fn test_get_block_info_eval_v210() { ASTRules::PrecheckSize, ); if let Err(ClarityError::Analysis(check_error)) = res { - if let CheckErrors::NoSuchBlockInfoProperty(name) = check_error.err { + if let CheckErrors::NoSuchBlockInfoProperty(name) = *check_error.err { assert_eq!(name, "block-reward"); } else { panic!("Bad analysis error: {:?}", &check_error); @@ -205,7 +205,7 @@ fn test_get_block_info_eval_v210() { ASTRules::PrecheckSize, ); if let Err(ClarityError::Analysis(check_error)) = res { - if let CheckErrors::NoSuchBlockInfoProperty(name) = check_error.err { + if let CheckErrors::NoSuchBlockInfoProperty(name) = *check_error.err { assert_eq!(name, "block-reward"); } else { panic!("Bad analysis error: {:?}", &check_error); @@ -219,7 +219,7 @@ fn test_get_block_info_eval_v210() { sim.execute_next_block_as_conn(|conn| { let contract_identifier = QualifiedContractIdentifier::local("test-contract-3").unwrap(); let contract = - "(define-private (test-func-1 (height uint)) (get-block-info? block-reward height)) + "(define-private (test-func-1 (height uint)) (get-block-info? block-reward height)) (define-private (test-func-2 (height uint)) (get-block-info? miner-spend-winner height)) (define-private (test-func-3 (height uint)) (get-block-info? miner-spend-total height))"; let epoch = conn.get_epoch(); @@ -249,7 +249,7 @@ fn test_get_block_info_eval_v210() { tx.eval_read_only(&contract_identifier, "(test-func-3 u0)") .unwrap() ); - // only works at the first block and later (not the 0th block) + // only works at the first block and later (not the 0th block) assert_eq!( Value::some(Value::UInt(3000)).unwrap(), tx.eval_read_only(&contract_identifier, "(test-func-1 u1)") @@ -367,7 +367,7 @@ fn trait_invocation_205_with_stored_principal() { let error = publish_contract(conn, &invoke_contract_id, invoke_contract, clarity_version) .unwrap_err(); match error { - ClarityError::Analysis(ref e) => match e.err { + ClarityError::Analysis(ref e) => match *e.err { CheckErrors::TypeError(..) => (), _ => panic!("Unexpected error: {:?}", error), }, @@ -461,8 +461,8 @@ fn trait_invocation_cross_epoch() { ) .unwrap_err(); - if let ClarityError::Interpreter(Error::Unchecked(CheckErrors::TypeValueError(TypeSignature::TraitReferenceType(_), value))) = error { - // pass + if let ClarityError::Interpreter(Error::Unchecked(CheckErrors::TypeValueError(trait_ref_type, value))) = error { + assert!(matches!(*trait_ref_type, TypeSignature::TraitReferenceType(_))); } else { panic!("Expected an Interpreter(UncheckedError(TypeValue(TraitReferenceType, Principal))) during Epoch-2.2"); }; @@ -485,8 +485,8 @@ fn trait_invocation_cross_epoch() { ) .unwrap_err(); - if let ClarityError::Interpreter(Error::Unchecked(CheckErrors::TypeValueError(TypeSignature::TraitReferenceType(_), value))) = error { - // pass + if let ClarityError::Interpreter(Error::Unchecked(CheckErrors::TypeValueError(trait_ref_type, value))) = error { + assert!(matches!(*trait_ref_type, TypeSignature::TraitReferenceType(_))); } else { panic!("Expected an Interpreter(UncheckedError(TypeValue(TraitReferenceType, Principal))) during Epoch-2.2"); }; @@ -936,7 +936,7 @@ fn test_block_heights() { ASTRules::PrecheckSize, ); if let Err(ClarityError::Analysis(check_error)) = res { - if let CheckErrors::UndefinedVariable(var_name) = check_error.err { + if let CheckErrors::UndefinedVariable(var_name) = *check_error.err { assert_eq!(var_name, "stacks-block-height"); } else { panic!("Bad analysis error: {:?}", &check_error); @@ -972,7 +972,7 @@ fn test_block_heights() { ASTRules::PrecheckSize, ); if let Err(ClarityError::Analysis(check_error)) = res { - if let CheckErrors::UndefinedVariable(var_name) = check_error.err { + if let CheckErrors::UndefinedVariable(var_name) = *check_error.err { assert_eq!(var_name, "stacks-block-height"); } else { panic!("Bad analysis error: {:?}", &check_error); @@ -989,7 +989,7 @@ fn test_block_heights() { ASTRules::PrecheckSize, ); if let Err(ClarityError::Analysis(check_error)) = res { - if let CheckErrors::UndefinedVariable(var_name) = check_error.err { + if let CheckErrors::UndefinedVariable(var_name) = *check_error.err { assert_eq!(var_name, "block-height"); } else { panic!("Bad analysis error: {:?}", &check_error); diff --git a/stackslib/src/net/relay.rs b/stackslib/src/net/relay.rs index 99d87ad6421..36e6e752a1e 100644 --- a/stackslib/src/net/relay.rs +++ b/stackslib/src/net/relay.rs @@ -1844,7 +1844,7 @@ impl Relayer { ast_check_size(&contract_id, &contract_code_str, clarity_version, epoch_id); match ast_res { Ok(_) => {} - Err(parse_error) => match parse_error.err { + Err(parse_error) => match *parse_error.err { ParseErrors::ExpressionStackDepthTooDeep | ParseErrors::VaryExpressionStackDepthTooDeep => { // don't include this block From 1a45565e11a457ccaa3a2f954fb212c7a974af31 Mon Sep 17 00:00:00 2001 From: Francesco Leacche Date: Mon, 15 Sep 2025 16:36:31 +0200 Subject: [PATCH 2/2] box ExpectedContractPrincipalValue --- clarity-types/src/errors/analysis.rs | 2 +- .../type_checker/v2_1/tests/contracts.rs | 60 ++++++++++--------- clarity/src/vm/functions/database.rs | 4 +- clarity/src/vm/tests/contracts.rs | 4 +- 4 files changed, 37 insertions(+), 33 deletions(-) diff --git a/clarity-types/src/errors/analysis.rs b/clarity-types/src/errors/analysis.rs index 1e35c61cfbc..6c4d40ea377 100644 --- a/clarity-types/src/errors/analysis.rs +++ b/clarity-types/src/errors/analysis.rs @@ -195,7 +195,7 @@ pub enum CheckErrors { CouldNotDetermineResponseErrType, CouldNotDetermineSerializationType, UncheckedIntermediaryResponses, - ExpectedContractPrincipalValue(Value), + ExpectedContractPrincipalValue(Box), CouldNotDetermineMatchTypes, CouldNotDetermineType, diff --git a/clarity/src/vm/analysis/type_checker/v2_1/tests/contracts.rs b/clarity/src/vm/analysis/type_checker/v2_1/tests/contracts.rs index 61cbe6c31ce..b56caeb740c 100644 --- a/clarity/src/vm/analysis/type_checker/v2_1/tests/contracts.rs +++ b/clarity/src/vm/analysis/type_checker/v2_1/tests/contracts.rs @@ -283,7 +283,7 @@ fn test_names_tokens_contracts_interface() { {{ "name": "tn1", "type": "bool" }}, {{ "name": "tn2", "type": "int128" }}, {{ "name": "tn3", "type": {{ "buffer": {{ "length": 1 }} }}}} - ] }} }} + ] }} }} }}, {{ "name": "f11", "access": "private", @@ -416,7 +416,7 @@ fn test_names_tokens_contracts_interface() { "name": "n2", "type": "bool" }} - ] + ] }} }}] }} @@ -3374,43 +3374,43 @@ fn test_contract_hash(#[case] version: ClarityVersion, #[case] epoch: StacksEpoc "(contract-hash? 123)", "int type", Err(CheckErrors::TypeError( - TypeSignature::PrincipalType, - TypeSignature::IntType, + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::IntType), )), ), ( "(contract-hash? u123)", "uint type", Err(CheckErrors::TypeError( - TypeSignature::PrincipalType, - TypeSignature::UIntType, + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::UIntType), )), ), ( "(contract-hash? true)", "bool type", Err(CheckErrors::TypeError( - TypeSignature::PrincipalType, - TypeSignature::BoolType, + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::BoolType), )), ), ( "(contract-hash? 0x1234)", "buffer type", Err(CheckErrors::TypeError( - TypeSignature::PrincipalType, - TypeSignature::SequenceType(SequenceSubtype::BufferType( + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::SequenceType(SequenceSubtype::BufferType( BufferLength::try_from(2u32).unwrap(), - )), + ))), )), ), ( "(contract-hash? \"60 percent of the time, it works every time\")", "ascii string", Err(CheckErrors::TypeError( - TypeSignature::PrincipalType, - TypeSignature::SequenceType(SequenceSubtype::StringType(StringSubtype::ASCII( - BufferLength::try_from(43u32).unwrap(), + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::SequenceType(SequenceSubtype::StringType( + StringSubtype::ASCII(BufferLength::try_from(43u32).unwrap()), ))), )), ), @@ -3418,9 +3418,9 @@ fn test_contract_hash(#[case] version: ClarityVersion, #[case] epoch: StacksEpoc "(contract-hash? u\"I am serious, and don't call me Shirley.\")", "utf8 string", Err(CheckErrors::TypeError( - TypeSignature::PrincipalType, - TypeSignature::SequenceType(SequenceSubtype::StringType(StringSubtype::UTF8( - StringUTF8Length::try_from(40u32).unwrap(), + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::SequenceType(SequenceSubtype::StringType( + StringSubtype::UTF8(StringUTF8Length::try_from(40u32).unwrap()), ))), )), ), @@ -3428,49 +3428,51 @@ fn test_contract_hash(#[case] version: ClarityVersion, #[case] epoch: StacksEpoc "(contract-hash? (list 1 2 3))", "list type", Err(CheckErrors::TypeError( - TypeSignature::PrincipalType, - TypeSignature::SequenceType(SequenceSubtype::ListType( + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::SequenceType(SequenceSubtype::ListType( ListTypeData::new_list(TypeSignature::IntType, 3).unwrap(), - )), + ))), )), ), ( "(contract-hash? { a: 1, b: u2 })", "tuple type", Err(CheckErrors::TypeError( - TypeSignature::PrincipalType, - TypeSignature::TupleType( + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::TupleType( vec![ (ClarityName::from("a"), TypeSignature::IntType), (ClarityName::from("b"), TypeSignature::UIntType), ] .try_into() .unwrap(), - ), + )), )), ), ( "(contract-hash? (some u789))", "optional type", Err(CheckErrors::TypeError( - TypeSignature::PrincipalType, - TypeSignature::new_option(TypeSignature::UIntType).unwrap(), + Box::new(TypeSignature::PrincipalType), + Box::new(TypeSignature::new_option(TypeSignature::UIntType).unwrap()), )), ), ( "(contract-hash? (ok true))", "response type", Err(CheckErrors::TypeError( - TypeSignature::PrincipalType, - TypeSignature::new_response(TypeSignature::BoolType, TypeSignature::NoType) - .unwrap(), + Box::new(TypeSignature::PrincipalType), + Box::new( + TypeSignature::new_response(TypeSignature::BoolType, TypeSignature::NoType) + .unwrap(), + ), )), ), ]; for (source, description, clarity4_expected) in test_cases.iter() { let result = mem_run_analysis(source, version, epoch); - let actual = result.map(|(type_sig, _)| type_sig).map_err(|e| e.err); + let actual = result.map(|(type_sig, _)| type_sig).map_err(|e| *e.err); let expected = if version >= ClarityVersion::Clarity4 { clarity4_expected diff --git a/clarity/src/vm/functions/database.rs b/clarity/src/vm/functions/database.rs index ba696f7c448..93fbef0258e 100644 --- a/clarity/src/vm/functions/database.rs +++ b/clarity/src/vm/functions/database.rs @@ -1186,7 +1186,9 @@ pub fn special_contract_hash( Value::Principal(PrincipalData::Contract(contract_identifier)) => contract_identifier, _ => { // If the value is not a principal, we return a check error. - return Err(CheckErrors::ExpectedContractPrincipalValue(contract_value).into()); + return Err( + CheckErrors::ExpectedContractPrincipalValue(Box::new(contract_value)).into(), + ); } }; diff --git a/clarity/src/vm/tests/contracts.rs b/clarity/src/vm/tests/contracts.rs index 03281436985..da9d4f37318 100644 --- a/clarity/src/vm/tests/contracts.rs +++ b/clarity/src/vm/tests/contracts.rs @@ -1382,8 +1382,8 @@ fn test_contract_hash_type_check( .unwrap_err(); assert_eq!( err, - Error::Unchecked(CheckErrors::ExpectedContractPrincipalValue(Value::UInt( - 123 + Error::Unchecked(CheckErrors::ExpectedContractPrincipalValue(Box::new( + Value::UInt(123) ))) ); }