fix: only allow casting on top level Data
This commit is contained in:
@@ -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#"
|
||||
|
||||
Reference in New Issue
Block a user