Guard against setters mutating constants, and allow pure setters.

This commit is contained in:
Stephen Chung
2021-05-15 11:41:42 +08:00
parent 565134c4da
commit 941e09d29d
15 changed files with 184 additions and 156 deletions

View File

@@ -550,13 +550,6 @@ impl ExportedFn {
"property setter cannot return any value",
))
}
// 3c. Property setters cannot be pure.
FnSpecialAccess::Property(Property::Set(_)) if params.pure.is_some() => {
return Err(syn::Error::new(
params.pure.unwrap(),
"property setter cannot be pure",
))
}
// 4a. Index getters must take the subject and the accessed "index" as arguments.
FnSpecialAccess::Index(Index::Get) if self.arg_count() != 2 => {
return Err(syn::Error::new(
@@ -587,13 +580,6 @@ impl ExportedFn {
"index setter cannot return any value",
))
}
// 5b. Index setters cannot be pure.
FnSpecialAccess::Index(Index::Set) if params.pure.is_some() => {
return Err(syn::Error::new(
params.pure.unwrap(),
"index setter cannot be pure",
))
}
_ => {}
}
@@ -711,9 +697,7 @@ impl ExportedFn {
unpack_statements.push(
syn::parse2::<syn::Stmt>(quote! {
if args[0usize].is_read_only() {
return Err(Box::new(
EvalAltResult::ErrorAssignmentToConstant(#arg_lit_str.to_string(), Position::NONE)
));
return EvalAltResult::ErrorAssignmentToConstant(#arg_lit_str.to_string(), Position::NONE).into();
}
})
.unwrap(),