Skip to content

Commit

Permalink
Fixes for clippy & code in unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
kaleidawave committed Nov 13, 2024
1 parent ebae1bb commit 8066d22
Show file tree
Hide file tree
Showing 12 changed files with 250 additions and 240 deletions.
166 changes: 79 additions & 87 deletions checker/src/context/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,41 +301,38 @@ impl<'a> Environment<'a> {
checking_data.options.strict_casts,
checking_data.options.advanced_number_intrinsics,
);
match result {
Ok(new) => {
let assignment_position =
assignment_position.with_source(self.get_source());

self.set_reference_handle_errors(
reference,
new,
assignment_position,
checking_data,
);

new
}
Err(()) => {
checking_data.diagnostics_container.add_error(
crate::TypeCheckError::InvalidMathematicalOrBitwiseOperation {
operator,
lhs: crate::diagnostics::TypeStringRepresentation::from_type_id(
existing,
self,
&checking_data.types,
false,
),
rhs: crate::diagnostics::TypeStringRepresentation::from_type_id(
rhs,
self,
&checking_data.types,
false,
),
position: assignment_position.with_source(self.get_source()),
},
);
TypeId::ERROR_TYPE
}
if let Ok(new) = result {
let assignment_position =
assignment_position.with_source(self.get_source());

self.set_reference_handle_errors(
reference,
new,
assignment_position,
checking_data,
);

new
} else {
checking_data.diagnostics_container.add_error(
crate::TypeCheckError::InvalidMathematicalOrBitwiseOperation {
operator,
lhs: crate::diagnostics::TypeStringRepresentation::from_type_id(
existing,
self,
&checking_data.types,
false,
),
rhs: crate::diagnostics::TypeStringRepresentation::from_type_id(
rhs,
self,
&checking_data.types,
false,
),
position: assignment_position.with_source(self.get_source()),
},
);
TypeId::ERROR_TYPE
}
}
AssignmentKind::IncrementOrDecrement(direction, return_kind) => {
Expand Down Expand Up @@ -365,44 +362,41 @@ impl<'a> Environment<'a> {
checking_data.options.strict_casts,
checking_data.options.advanced_number_intrinsics,
);
match result {
Ok(new) => {
let assignment_position =
assignment_position.with_source(self.get_source());

self.set_reference_handle_errors(
reference,
new,
assignment_position,
checking_data,
);

match return_kind {
AssignmentReturnStatus::Previous => existing,
AssignmentReturnStatus::New => new,
}
}
Err(()) => {
checking_data.diagnostics_container.add_error(
crate::TypeCheckError::InvalidMathematicalOrBitwiseOperation {
operator,
lhs: crate::diagnostics::TypeStringRepresentation::from_type_id(
existing,
self,
&checking_data.types,
false,
),
rhs: crate::diagnostics::TypeStringRepresentation::from_type_id(
TypeId::ONE,
self,
&checking_data.types,
false,
),
position,
},
);
TypeId::ERROR_TYPE
if let Ok(new) = result {
let assignment_position =
assignment_position.with_source(self.get_source());

self.set_reference_handle_errors(
reference,
new,
assignment_position,
checking_data,
);

match return_kind {
AssignmentReturnStatus::Previous => existing,
AssignmentReturnStatus::New => new,
}
} else {
checking_data.diagnostics_container.add_error(
crate::TypeCheckError::InvalidMathematicalOrBitwiseOperation {
operator,
lhs: crate::diagnostics::TypeStringRepresentation::from_type_id(
existing,
self,
&checking_data.types,
false,
),
rhs: crate::diagnostics::TypeStringRepresentation::from_type_id(
TypeId::ONE,
self,
&checking_data.types,
false,
),
position,
},
);
TypeId::ERROR_TYPE
}
}
AssignmentKind::ConditionalUpdate(operator) => {
Expand Down Expand Up @@ -966,22 +960,20 @@ impl<'a> Environment<'a> {
// };

return Ok(VariableWithValue(og_var.clone(), precise));
}

crate::utilities::notify!("Free variable with no current value");
let constraint = checking_data
.local_type_mappings
.variables_to_constraints
.0
.get(&og_var.get_origin_variable_id());

if let Some(constraint) = constraint {
*constraint
} else {
crate::utilities::notify!("Free variable with no current value");
let constraint = checking_data
.local_type_mappings
.variables_to_constraints
.0
.get(&og_var.get_origin_variable_id());

if let Some(constraint) = constraint {
*constraint
} else {
crate::utilities::notify!(
"TODO record that free variable is `any` here"
);
TypeId::ANY_TYPE
}
crate::utilities::notify!("TODO record that free variable is `any` here");
TypeId::ANY_TYPE
}
}
VariableMutability::Mutable { reassignment_constraint } => {
Expand Down
4 changes: 2 additions & 2 deletions checker/src/context/information.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ pub fn merge_info(

// TODO temp fix for `... ? { ... } : { ... }`.
// TODO add undefineds to sides etc
for (on, properties) in truthy.current_properties.into_iter() {
for (on, properties) in truthy.current_properties {
// let properties = properties
// .into_iter()
// .map(|(publicity, key, value)| {
Expand All @@ -447,7 +447,7 @@ pub fn merge_info(
}

if let Some(otherwise) = otherwise {
for (on, properties) in otherwise.current_properties.into_iter() {
for (on, properties) in otherwise.current_properties {
if let Some(existing) = onto.current_properties.get_mut(&on) {
existing.extend(properties);
} else {
Expand Down
6 changes: 3 additions & 3 deletions checker/src/features/narrowing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ pub fn narrow_based_on_expression(
);

// TODO also from == x - 1 etc
let narrowed_to = if rhs != TypeId::ZERO {
let narrowed_to = if rhs == TypeId::ZERO {
narrowed_to
} else {
types.register_type(Type::Constructor(
crate::types::Constructor::BinaryOperator {
lhs: narrowed_to,
Expand All @@ -109,8 +111,6 @@ pub fn narrow_based_on_expression(
result: TypeId::NUMBER_TYPE,
},
))
} else {
narrowed_to
};
into.insert(operand, narrowed_to);
} else {
Expand Down
Loading

0 comments on commit 8066d22

Please sign in to comment.