Forbid non-serializable inhabitants in compound data-types.

This commit is contained in:
KtorZ
2024-03-09 22:23:44 +01:00
parent 37627e3527
commit ee54266d1f
4 changed files with 131 additions and 5 deletions

View File

@@ -122,6 +122,70 @@ fn validator_illegal_arity() {
))
}
#[test]
fn list_illegal_inhabitants() {
let source_code = r#"
fn main() {
[identity]
}
"#;
assert!(matches!(
check_validator(parse(source_code)),
Err((_, Error::IllegalTypeInData { .. }))
))
}
#[test]
fn tuple_illegal_inhabitants() {
let source_code = r#"
fn main() {
(identity, always)
}
"#;
assert!(matches!(
check_validator(parse(source_code)),
Err((_, Error::IllegalTypeInData { .. }))
))
}
#[test]
fn illegal_inhabitants_nested() {
let source_code = r#"
fn main() {
[(identity, always)]
}
"#;
assert!(matches!(
check_validator(parse(source_code)),
Err((_, Error::IllegalTypeInData { .. }))
))
}
#[test]
fn illegal_inhabitants_returned() {
let source_code = r#"
type Fuzzer<a> = fn(PRNG) -> (a, PRNG)
fn constant(a: a) -> Fuzzer<a> {
fn (prng) {
(a, prng)
}
}
fn main() -> Fuzzer<Fuzzer<Int>> {
constant(constant(42))
}
"#;
assert!(matches!(
check_validator(parse(source_code)),
Err((_, Error::IllegalTypeInData { .. }))
))
}
#[test]
fn mark_constructors_as_used_via_field_access() {
let source_code = r#"