fix: only allow casting on top level Data

This commit is contained in:
rvcas
2024-03-21 11:53:49 -04:00
committed by Lucas
parent c20ff6b160
commit ee280bc309
2 changed files with 45 additions and 7 deletions

View File

@@ -1847,6 +1847,44 @@ fn allow_expect_into_type_from_data() {
assert!(check(parse(source_code)).is_ok())
}
#[test]
fn forbid_partial_down_casting() {
let source_code = r#"
type Foo {
x: Int
}
fn bar(n: List<Foo>) {
expect a: List<Data> = n
a
}
"#;
assert!(matches!(
dbg!(check(parse(source_code))),
Err((_, Error::CouldNotUnify { .. }))
))
}
#[test]
fn forbid_partial_up_casting() {
let source_code = r#"
type Foo {
x: Int
}
fn bar(n: List<Data>) {
expect a: List<Foo> = n
a
}
"#;
assert!(matches!(
dbg!(check(parse(source_code))),
Err((_, Error::CouldNotUnify { .. }))
))
}
#[test]
fn allow_expect_into_type_from_data_2() {
let source_code = r#"