Invalidate rendering when typed method storage is shadowed
This commit is contained in:
@@ -3938,6 +3938,62 @@ page.render(block)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn typed_method_shadows_invalidate_cached_ancestors_and_can_be_removed() {
|
||||
let mut session = ReplSession::new(233).unwrap();
|
||||
session
|
||||
.execute(
|
||||
"rect = RectBlock(40, 20) root = ColumnBlock(0, 0, rect)",
|
||||
"app.main",
|
||||
)
|
||||
.unwrap();
|
||||
let globals = session.candidate.globals.unwrap();
|
||||
let lookup = |name: &str| match session
|
||||
.candidate
|
||||
.vm
|
||||
.dict_get(globals, &Value::Text(name.into()))
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
{
|
||||
Value::Object(value) => value,
|
||||
_ => panic!("object"),
|
||||
};
|
||||
let rect = lookup("rect");
|
||||
let root = lookup("root");
|
||||
for name in ["paint", "measure", "onEvent"] {
|
||||
let error = session
|
||||
.execute(&format!("rect.{name} = 1"), "app.main")
|
||||
.err()
|
||||
.expect("typed method cannot be shadowed");
|
||||
assert!(
|
||||
error.to_string().contains("instance attribute shadows"),
|
||||
"{error:#}"
|
||||
);
|
||||
}
|
||||
let vm = &mut session.candidate.vm;
|
||||
let storage = *vm
|
||||
.object_store()
|
||||
.attribute_path(rect)
|
||||
.unwrap()
|
||||
.last()
|
||||
.unwrap();
|
||||
let mut cache = crate::snapshot::RenderCache::default();
|
||||
cache.snapshot(vm.object_store(), root).unwrap();
|
||||
vm.take_changes();
|
||||
cache.snapshot(vm.object_store(), root).unwrap();
|
||||
assert_eq!(cache.visited, 0);
|
||||
vm.set_attr(storage, "paint", Value::Nil).unwrap();
|
||||
cache.invalidate(vm.take_changes());
|
||||
assert!(matches!(
|
||||
cache.snapshot(vm.object_store(), root),
|
||||
Err(endor_core::VmError::TraitViolation { .. })
|
||||
));
|
||||
vm.del_attr(storage, "paint").unwrap();
|
||||
cache.invalidate(vm.take_changes());
|
||||
cache.snapshot(vm.object_store(), root).unwrap();
|
||||
assert!(cache.visited > 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn presentable_type_contracts_reject_before_registration_or_body_effects() {
|
||||
let mut session = ReplSession::new(232).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user