Compare commits

..

1 Commits

Author SHA1 Message Date
David Mak db88c3a78e core: Refactor to return errors by HashSet 2023-12-12 13:51:33 +08:00
4 changed files with 27 additions and 27 deletions

View File

@ -384,7 +384,7 @@ pub fn parse_type_annotation<T>(
"Unexpected number of type parameters: expected {} but got 0",
type_vars.len()
),
]));
]))
}
let fields = chain(
fields.iter().map(|(k, v, m)| (*k, (*v, *m))),
@ -460,7 +460,7 @@ pub fn parse_type_annotation<T>(
type_vars.len(),
types.len()
),
]));
]))
}
let mut subst = HashMap::new();
for (var, ty) in izip!(type_vars.iter(), types.iter()) {

View File

@ -422,7 +422,7 @@ impl TopLevelComposer {
"only single Generic[...] is allowed (at {})",
b.location
),
]));
]))
}
is_generic = true;
@ -466,7 +466,7 @@ impl TopLevelComposer {
"duplicate type variable occurs (at {})",
slice.location
),
]));
]))
}
// add to TopLevelDef
@ -552,7 +552,7 @@ impl TopLevelComposer {
declaration and one generic declaration (at {})",
b.location
),
]));
]))
}
has_base = true;
@ -576,7 +576,7 @@ impl TopLevelComposer {
"class base declaration can only be custom class (at {})",
b.location,
),
]));
]))
}
}
Ok(())
@ -667,7 +667,7 @@ impl TopLevelComposer {
) {
return Err(HashSet::from([
"Classes inherited from exception should have no custom fields/methods".into()
]));
]))
}
}
} else {
@ -825,7 +825,7 @@ impl TopLevelComposer {
let primitives_store = &self.primitives_ty;
let mut errors = HashSet::new();
let mut analyze = |function_def: &Arc<RwLock<TopLevelDef>>, function_ast: &Option<Stmt>| -> Result<(), HashSet<String>> {
let mut analyze = |function_def: &Arc<RwLock<TopLevelDef>>, function_ast: &Option<Stmt>| {
let mut function_def = function_def.write();
let function_def = &mut *function_def;
let Some(function_ast) = function_ast.as_ref() else {
@ -859,7 +859,7 @@ impl TopLevelComposer {
and names should not be the same as the keywords (at {})",
x.location
),
]));
]))
}
}
@ -1484,7 +1484,7 @@ impl TopLevelComposer {
format!(
"field `{class_field_name}` has already declared in the ancestor classes"
),
]));
]))
}
}
new_child_fields.push(to_be_added);
@ -1664,7 +1664,7 @@ impl TopLevelComposer {
class_name,
body[0].location,
),
]));
]))
}
}
}
@ -1681,7 +1681,7 @@ impl TopLevelComposer {
}
}
if !errors.is_empty() {
return Err(errors);
return Err(errors)
}
for (i, signature, id) in constructors {
@ -1898,7 +1898,7 @@ impl TopLevelComposer {
} else {
return Err(HashSet::from([
format!("Base type should be a class (at {loc})"),
]));
]))
}
};
let subtype_id = {
@ -1912,7 +1912,7 @@ impl TopLevelComposer {
format!(
"Expected a subtype of {base_repr}, but got {subtype_repr} (at {loc})"
),
]));
]))
}
};
let subtype_entry = defs[subtype_id.0].read();
@ -1926,7 +1926,7 @@ impl TopLevelComposer {
format!(
"Expected a subtype of {base_repr}, but got {subtype_repr} (at {loc})"
),
]));
]))
}
} else {
unreachable!();
@ -1956,7 +1956,7 @@ impl TopLevelComposer {
name,
ast.as_ref().unwrap().location
),
]));
]))
}
instance_to_stmt.insert(
@ -1984,7 +1984,7 @@ impl TopLevelComposer {
}
}
if !errors.is_empty() {
return Err(errors);
return Err(errors)
}
Ok(())
}

View File

@ -114,7 +114,7 @@ pub fn parse_ast_to_type_annotation_kinds<T>(
"function cannot be used as a type (at {})",
expr.location
),
]));
]))
}
} else {
locked.get(&obj_id).unwrap().clone()
@ -128,7 +128,7 @@ pub fn parse_ast_to_type_annotation_kinds<T>(
type_vars.len(),
expr.location,
),
]));
]))
}
Ok(TypeAnnotation::CustomClass { id: obj_id, params: vec![] })
} else if let Ok(ty) = resolver.get_symbol_type(unifier, top_level_defs, primitives, *id) {
@ -157,7 +157,7 @@ pub fn parse_ast_to_type_annotation_kinds<T>(
{
return Err(HashSet::from([
format!("keywords cannot be class name (at {})", expr.location),
]));
]))
}
let obj_id = resolver.get_identifier_def(*id)?;
let type_vars = {
@ -187,7 +187,7 @@ pub fn parse_ast_to_type_annotation_kinds<T>(
params_ast.len(),
params_ast[0].location,
),
]));
]))
}
let result = params_ast
.iter()
@ -218,7 +218,7 @@ pub fn parse_ast_to_type_annotation_kinds<T>(
"application of type vars to generic class is not currently supported (at {})",
params_ast[0].location
),
]));
]))
}
};
Ok(TypeAnnotation::CustomClass { id: obj_id, params: param_type_infos })
@ -434,7 +434,7 @@ pub fn get_type_from_type_annotation_kinds(
),
*id
)
]));
]))
}
}

View File

@ -49,7 +49,7 @@ impl<'a> Inferencer<'a> {
"Error at {}: cannot assign to tuple element",
value.location
),
]));
]))
}
Ok(())
}
@ -76,7 +76,7 @@ impl<'a> Inferencer<'a> {
expr.location,
self.unifier.get_ty(*ty).get_type_name()
)
]));
]))
}
}
match &expr.node {
@ -101,7 +101,7 @@ impl<'a> Inferencer<'a> {
"type error at identifier `{}` ({}) at {}",
id, e, expr.location
)
]));
]))
}
}
}
@ -137,7 +137,7 @@ impl<'a> Inferencer<'a> {
"shift count is negative at {}",
right.location
),
]));
]))
}
}
}