Register typed GUI capabilities and reject incompatible presenters early

This commit is contained in:
2026-10-22 14:37:43 +08:00
parent 579b6f8bec
commit 8b698cb39f
6 changed files with 102 additions and 19 deletions
+54
View File
@@ -3837,6 +3837,60 @@ page.render(block)
);
}
#[test]
fn presentable_type_contracts_reject_before_registration_or_body_effects() {
let mut session = ReplSession::new(232).unwrap();
session.execute("marker = ui.state(0)", "app.main").unwrap();
for (name, method) in [
(
"WrongParameter",
"function present(self: WrongParameter, window: Point): Block { marker.increment() return TextBlock(\"bad\") }",
),
(
"WrongResult",
"function present(self: WrongResult, window: Window): Number { marker.increment() return 7 }",
),
] {
let input = format!("class {name} {{ {method} }} ui.implement({name}, Presentable)");
let error = session
.execute(&input, "app.main")
.err()
.expect("incompatible typed capability");
assert!(
error
.to_string()
.contains("trait Presentable method present"),
"{error:#}"
);
assert_eq!(
session
.execute(&format!("ui.implements({name}, Presentable)"), "app.main")
.unwrap()
.value,
"false"
);
assert_eq!(
session.execute("marker.value", "app.main").unwrap().value,
"0"
);
}
session.execute(r#"
class Good {
function present(self: Good, window: Object): TextBlock { return TextBlock("typed") }
}
ui.implement(Good, Presentable)
view = ui.present(Good())
"#, "app.main").unwrap();
assert_eq!(
session
.execute("ui.isInstance(view, TextBlock)", "app.main")
.unwrap()
.value,
"true"
);
assert!(!session.is_faulted());
}
#[test]
fn presentable_dispatch_preserves_source_identity_and_reactive_display() {
let (mut session, initial) = ReplSession::load(