Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] Adding the support for setters #94

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 45 additions & 5 deletions checker/src/types/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
behavior::functions::ThisValue,
context::{facts::Publicity, CallCheckingBehavior, Logical, SetPropertyError},
events::Event,
subtyping::{type_is_subtype, SubTypeResult},
subtyping::{type_is_subtype, NonEqualityReason, SubTypeResult},
types::{printing::print_type, substitute, FunctionType, StructureGenerics},
Constant, Environment, TypeId,
};
Expand Down Expand Up @@ -377,7 +377,7 @@ fn evaluate_get_on_poly<E: CallCheckingBehavior>(
result: getter.return_type,
})))
}
PropertyValue::Setter(_) => todo!("error"),
PropertyValue::Setter(setter) => None,
// Very important
PropertyValue::Deleted => None,
}
Expand Down Expand Up @@ -507,9 +507,49 @@ pub(crate) fn set_property<E: CallCheckingBehavior>(
position: setter_position,
});
}
PropertyValue::Getter(_) => todo!(),
PropertyValue::Setter(_setter) => {
todo!()
PropertyValue::Getter(_) => return Err(SetPropertyError::NotWriteable),
PropertyValue::Setter(setter) => {
// Setters must have 1 parameters, so it's supposed to be catch at parsing time
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! I had a thought to make it fixed in the parser with generics. But the additional complexity outweighed the benefit so it is just assumed!

let param = setter.parameters.parameters.get(0).unwrap();

let position = setter_position.unwrap_or(source_map::SpanWithSource::NULL_SPAN);

let mut basic_subtyping = crate::types::subtyping::BasicEquality {
add_property_restrictions: true,
position: position.clone(),
};

if let SubTypeResult::IsNotSubType(sub_type_error) = type_is_subtype(
param.ty,
new.as_get_type(),
&mut basic_subtyping,
environment,
types,
) {
// TODO don't short circuit
return Err(SetPropertyError::DoesNotMeetConstraint(
param.ty,
sub_type_error,
));
}

let facts = behavior.get_top_level_facts(environment);

facts.current_properties.entry(on).or_default().push((
publicity,
under.into_owned(),
new.clone(),
));
facts.events.push(Event::Setter {
on,
new,
under: under.into_owned(),
publicity,
// TODO
reflects_dependency: None,
initialization: false,
position: Some(position),
});
}
},
Logical::Or { .. } => todo!(),
Expand Down