Adopt checked source method overrides and document variance contracts

This commit is contained in:
2026-10-22 14:14:08 +08:00
parent d9fd3f2f65
commit 579b6f8bec
6 changed files with 77 additions and 7 deletions
+41
View File
@@ -2951,6 +2951,47 @@ page.render(block)
assert!(session.refresh_document().unwrap().is_none());
}
#[test]
fn source_overrides_accept_wider_inputs_and_more_specific_results() {
let source = include_str!("../examples/method-contracts.endor");
let (mut session, document) = ReplSession::load(source, "app.main", 164, 1).unwrap();
document.validate().unwrap();
assert_eq!(
session
.execute("rect.mounts().at(0).bounds().width", "app.main")
.unwrap()
.value,
"180"
);
session.execute("button.click()", "app.main").unwrap();
assert_eq!(
session
.execute("rect.mounts().at(0).bounds().width", "app.main")
.unwrap()
.value,
"260"
);
assert_eq!(
session.execute("count.value", "app.main").unwrap().value,
"1"
);
for (source, reason) in [
(
source.replace("mount: Object", "mount: Point"),
"override narrows a parameter type",
),
(
source.replace("): Sized {", "): Object {"),
"override widens the return type",
),
] {
let error = ReplSession::load(&source, "app.main", 165, 1)
.err()
.expect("invalid override");
assert!(error.to_string().contains(reason), "{error:#}");
}
}
#[test]
fn nullable_page_methods_union_event_options_and_nominal_mount_bounds_compose() {
let (mut session, _) = ReplSession::load(