Skip to content

Commit b1332a7

Browse files
authored
Merge pull request #6494 from Jiloc/chore/remove-unused-check-errors-variants
chore: remove unused `CheckErrors`' variants
2 parents ae2d105 + 985bb03 commit b1332a7

File tree

2 files changed

+35
-34
lines changed

2 files changed

+35
-34
lines changed

clarity-types/src/errors/analysis.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -165,24 +165,20 @@ pub enum CheckErrors {
165165
BadMatchInput(Box<TypeSignature>),
166166

167167
// list typing errors
168-
UnknownListConstructionFailure,
169168
ListTypesMustMatch,
170169
ConstructedListTooLarge,
171170

172171
// simple type expectation mismatch
173172
TypeError(Box<TypeSignature>, Box<TypeSignature>),
174-
TypeLiteralError(Box<TypeSignature>, Box<TypeSignature>),
175173
TypeValueError(Box<TypeSignature>, Box<Value>),
176174

177-
NoSuperType(Box<TypeSignature>, Box<TypeSignature>),
178175
InvalidTypeDescription,
179176
UnknownTypeName(String),
180177

181178
// union type mismatch
182179
UnionTypeError(Vec<TypeSignature>, Box<TypeSignature>),
183180
UnionTypeValueError(Vec<TypeSignature>, Box<Value>),
184181

185-
ExpectedLiteral,
186182
ExpectedOptionalType(Box<TypeSignature>),
187183
ExpectedResponseType(Box<TypeSignature>),
188184
ExpectedOptionalOrResponseType(Box<TypeSignature>),
@@ -200,12 +196,10 @@ pub enum CheckErrors {
200196

201197
// Checker runtime failures
202198
TypeAlreadyAnnotatedFailure,
203-
TypeAnnotationExpectedFailure,
204199
CheckerImplementationFailure,
205200

206201
// Assets
207202
BadTokenName,
208-
DefineFTBadSignature,
209203
DefineNFTBadSignature,
210204
NoSuchNFT(String),
211205
NoSuchFT(String),
@@ -284,7 +278,6 @@ pub enum CheckErrors {
284278
IfArmsMustMatch(Box<TypeSignature>, Box<TypeSignature>),
285279
MatchArmsMustMatch(Box<TypeSignature>, Box<TypeSignature>),
286280
DefaultTypesMustMatch(Box<TypeSignature>, Box<TypeSignature>),
287-
TooManyExpressions,
288281
IllegalOrUnknownFunctionApplication(String),
289282
UnknownFunction(String),
290283

@@ -293,7 +286,6 @@ pub enum CheckErrors {
293286
TraitReferenceUnknown(String),
294287
TraitMethodUnknown(String, String),
295288
ExpectedTraitIdentifier,
296-
ImportTraitBadSignature,
297289
TraitReferenceNotAllowed,
298290
BadTraitImplementation(String, String),
299291
DefineTraitBadSignature,
@@ -496,7 +488,6 @@ fn formatted_expected_types(expected_types: &[TypeSignature]) -> String {
496488
impl DiagnosableError for CheckErrors {
497489
fn message(&self) -> String {
498490
match &self {
499-
CheckErrors::ExpectedLiteral => "expected a literal argument".into(),
500491
CheckErrors::SupertypeTooLarge => "supertype of two types is too large".into(),
501492
CheckErrors::Expects(s) => format!("unexpected interpreter behavior: {s}"),
502493
CheckErrors::BadMatchOptionSyntax(source) =>
@@ -507,7 +498,6 @@ impl DiagnosableError for CheckErrors {
507498
source.message()),
508499
CheckErrors::BadMatchInput(t) =>
509500
format!("match requires an input of either a response or optional, found input: '{t}'"),
510-
CheckErrors::TypeAnnotationExpectedFailure => "analysis expected type to already be annotated for expression".into(),
511501
CheckErrors::CostOverflow => "contract execution cost overflowed cost counter".into(),
512502
CheckErrors::CostBalanceExceeded(a, b) => format!("contract execution cost exceeded budget: {a:?} > {b:?}"),
513503
CheckErrors::MemoryBalanceExceeded(a, b) => format!("contract execution cost exceeded memory budget: {a:?} > {b:?}"),
@@ -518,12 +508,9 @@ impl DiagnosableError for CheckErrors {
518508
CheckErrors::ValueOutOfBounds => "created a type which value size was out of defined bounds".into(),
519509
CheckErrors::TypeSignatureTooDeep => "created a type which was deeper than maximum allowed type depth".into(),
520510
CheckErrors::ExpectedName => "expected a name argument to this function".into(),
521-
CheckErrors::NoSuperType(a, b) => format!("unable to create a supertype for the two types: '{a}' and '{b}'"),
522-
CheckErrors::UnknownListConstructionFailure => "invalid syntax for list definition".into(),
523511
CheckErrors::ListTypesMustMatch => "expecting elements of same type in a list".into(),
524512
CheckErrors::ConstructedListTooLarge => "reached limit of elements in a sequence".into(),
525513
CheckErrors::TypeError(expected_type, found_type) => format!("expecting expression of type '{expected_type}', found '{found_type}'"),
526-
CheckErrors::TypeLiteralError(expected_type, found_type) => format!("expecting a literal of type '{expected_type}', found '{found_type}'"),
527514
CheckErrors::TypeValueError(expected_type, found_value) => format!("expecting expression of type '{expected_type}', found '{found_value}'"),
528515
CheckErrors::UnionTypeError(expected_types, found_type) => format!("expecting expression of type {}, found '{}'", formatted_expected_types(expected_types), found_type),
529516
CheckErrors::UnionTypeValueError(expected_types, found_type) => format!("expecting expression of type {}, found '{}'", formatted_expected_types(expected_types), found_type),
@@ -588,21 +575,18 @@ impl DiagnosableError for CheckErrors {
588575
CheckErrors::IfArmsMustMatch(type_1, type_2) => format!("expression types returned by the arms of 'if' must match (got '{type_1}' and '{type_2}')"),
589576
CheckErrors::MatchArmsMustMatch(type_1, type_2) => format!("expression types returned by the arms of 'match' must match (got '{type_1}' and '{type_2}')"),
590577
CheckErrors::DefaultTypesMustMatch(type_1, type_2) => format!("expression types passed in 'default-to' must match (got '{type_1}' and '{type_2}')"),
591-
CheckErrors::TooManyExpressions => "reached limit of expressions".into(),
592578
CheckErrors::IllegalOrUnknownFunctionApplication(function_name) => format!("use of illegal / unresolved function '{function_name}"),
593579
CheckErrors::UnknownFunction(function_name) => format!("use of unresolved function '{function_name}'"),
594580
CheckErrors::TraitBasedContractCallInReadOnly => "use of trait based contract calls are not allowed in read-only context".into(),
595581
CheckErrors::WriteAttemptedInReadOnly => "expecting read-only statements, detected a writing operation".into(),
596582
CheckErrors::AtBlockClosureMustBeReadOnly => "(at-block ...) closures expect read-only statements, but detected a writing operation".into(),
597583
CheckErrors::BadTokenName => "expecting an token name as an argument".into(),
598-
CheckErrors::DefineFTBadSignature => "(define-token ...) expects a token name as an argument".into(),
599584
CheckErrors::DefineNFTBadSignature => "(define-asset ...) expects an asset name and an asset identifier type signature as arguments".into(),
600585
CheckErrors::NoSuchNFT(asset_name) => format!("tried to use asset function with a undefined asset ('{asset_name}')"),
601586
CheckErrors::NoSuchFT(asset_name) => format!("tried to use token function with a undefined token ('{asset_name}')"),
602587
CheckErrors::NoSuchTrait(contract_name, trait_name) => format!("use of unresolved trait {contract_name}.{trait_name}"),
603588
CheckErrors::TraitReferenceUnknown(trait_name) => format!("use of undeclared trait <{trait_name}>"),
604589
CheckErrors::TraitMethodUnknown(trait_name, func_name) => format!("method '{func_name}' unspecified in trait <{trait_name}>"),
605-
CheckErrors::ImportTraitBadSignature => "(use-trait ...) expects a trait name and a trait identifier".into(),
606590
CheckErrors::BadTraitImplementation(trait_name, func_name) => format!("invalid signature for method '{func_name}' regarding trait's specification <{trait_name}>"),
607591
CheckErrors::ExpectedTraitIdentifier => "expecting expression of type trait identifier".into(),
608592
CheckErrors::UnexpectedTraitOrFieldReference => "unexpected use of trait reference or field".into(),

clarity-types/src/types/signatures.rs

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -971,26 +971,43 @@ impl TypeSignature {
971971
}
972972
}
973973

974-
/// This function returns the most-restrictive type that admits _both_ A and B (something like a least common supertype),
975-
/// or Errors if no such type exists. On error, it throws NoSuperType(A,B), unless a constructor error'ed -- in which case,
976-
/// it throws the constructor's error.
974+
/// Returns the most-restrictive type that admits _both_ A and B (something like a least common supertype),
975+
/// or Errors if no such type exists. On error, it throws TypeError(A,B), unless a constructor error'ed,
976+
/// in which case, it throws SupertypeTooLarge.
977977
///
978-
/// For two Tuples:
979-
/// least_supertype(A, B) := (tuple \for_each(key k) least_supertype(type_a_k, type_b_k))
980-
/// For two Lists:
981-
/// least_supertype(A, B) := (list max_len: max(max_len A, max_len B), entry: least_supertype(entry_a, entry_b))
982-
/// if max_len A | max_len B is 0: entry := Non-empty list entry
983-
/// For two responses:
984-
/// least_supertype(A, B) := (response least_supertype(ok_a, ok_b), least_supertype(err_a, err_b))
985-
/// if any entries are NoType, use the other type's entry
986-
/// For two options:
987-
/// least_supertype(A, B) := (option least_supertype(some_a, some_b))
988-
/// if some_a | some_b is NoType, use the other type's entry.
989-
/// For buffers:
990-
/// least_supertype(A, B) := (buff len: max(len A, len B))
991-
/// For ints, uints, principals, bools:
992-
/// least_supertype(A, B) := if A != B, error, else A
978+
/// The behavior varies by epoch:
979+
/// - Epoch 2.0/2.05: Uses [`TypeSignature::least_supertype_v2_0`]
980+
/// - Epoch 2.1+: Uses [`TypeSignature::least_supertype_v2_1`], Adds support for CallableTypes and ListUnionTypes
993981
///
982+
/// For two Tuples:
983+
/// least_supertype(A, B) := (tuple \for_each(key k) least_supertype(type_a_k, type_b_k))
984+
/// Note: `A`'s keys must be a subset of `B`'s.
985+
/// For two Lists:
986+
/// least_supertype(A, B) := (list max_len: max(max_len A, max_len B), entry: least_supertype(entry_a, entry_b))
987+
/// If max_len A | max_len B is 0: entry := Non-empty list entry
988+
/// For two Responses:
989+
/// least_supertype(A, B) := (response least_supertype(ok_a, ok_b), least_supertype(err_a, err_b))
990+
/// If any entries are NoType, use the other type's entry
991+
/// For two Options:
992+
/// least_supertype(A, B) := (option least_supertype(some_a, some_b))
993+
/// If some_a | some_b is NoType, use the other type's entry
994+
/// For Buffers:
995+
/// least_supertype(A, B) := (buff len: max(len A, len B))
996+
/// For ASCII/UTF8 Strings:
997+
/// least_supertype(A, B) := (string len: max(len A, len B))
998+
/// Note: ASCII and UTF8 strings cannot be unified
999+
/// For NoType:
1000+
/// least_supertype(NoType, X) := X
1001+
/// For CallableTypes (v2.1+ only):
1002+
/// - Two identical CallableTypes unify to themselves
1003+
/// - Two different CallableTypes unify to a ListUnionType containing both
1004+
/// - CallableType and ListUnionType unify by adding the callable to the union
1005+
/// - Principal type unifies with CallableSubtype::Principal(_) to PrincipalType
1006+
/// - Principal type unifies with ListUnionType if all members are principals
1007+
/// For ListUnionTypes (v2.1+ only):
1008+
/// least_supertype(A, B) := ListUnionType with the union of both sets
1009+
/// For other types (ints, uints, principals, bools):
1010+
/// least_supertype(A, B) := if A != B, error, else A
9941011
pub fn least_supertype(
9951012
epoch: &StacksEpochId,
9961013
a: &TypeSignature,

0 commit comments

Comments
 (0)