Check for args length when comparing types. Duh!

Fixes #917.
This commit is contained in:
KtorZ 2024-05-01 10:45:48 +02:00
parent 945a3f743b
commit 925a11be69
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
3 changed files with 60 additions and 1 deletions

View File

@ -13,6 +13,7 @@
- **aiken-lang**: formatter should not erase `pub` on validators. @rvcas
- **aiken-lang**: error on using tuple index when a tuple is returned by a generic function. @rvcas
- **aiken-lang**: fix a regression in the Type-checker introduced in v1.0.25-alpha regarding types comparison. See #917. @KtorZ
## v1.0.26-alpha - 2024-03-25

View File

@ -2295,3 +2295,57 @@ fn tuple_access_on_call() {
assert!(check(parse(source_code)).is_ok())
}
#[test]
fn partial_eq_call_args() {
let source_code = r#"
fn foo(a: Int, b: Int, c: Bool) -> Int {
todo
}
fn main() -> Int {
foo(14, 42)
}
"#;
assert!(matches!(
dbg!(check(parse(source_code))),
Err((_, Error::IncorrectFieldsArity { .. }))
));
}
#[test]
fn partial_eq_callback_args() {
let source_code = r#"
fn foo(cb: fn(Int, Int, Bool) -> Int) -> Int {
todo
}
fn main() -> Int {
foo(fn(a, b) { a + b })
}
"#;
assert!(matches!(
dbg!(check(parse(source_code))),
Err((_, Error::CouldNotUnify { .. }))
));
}
#[test]
fn partial_eq_callback_return() {
let source_code = r#"
fn foo(cb: fn(Int, Int) -> (Int, Int, Bool)) -> Int {
todo
}
fn main() -> Int {
foo(fn(a, b) { (a, b) })
}
"#;
assert!(matches!(
dbg!(check(parse(source_code))),
Err((_, Error::CouldNotUnify { .. }))
));
}

View File

@ -96,6 +96,7 @@ impl PartialEq for Type {
name == name2
&& module == module2
&& public == public2
&& args.len() == args2.len()
&& args.iter().zip(args2).all(|(left, right)| left == right)
} else {
false
@ -109,7 +110,9 @@ impl PartialEq for Type {
alias: _,
} = other
{
ret == ret2 && args.iter().zip(args2).all(|(left, right)| left == right)
ret == ret2
&& args.len() == args2.len()
&& args.iter().zip(args2).all(|(left, right)| left == right)
} else {
false
}
@ -117,6 +120,7 @@ impl PartialEq for Type {
Type::Tuple { elems, alias: _ } => {
if let Type::Tuple { elems: elems2, .. } = other {
elems.len() == elems2.len() &&
elems.iter().zip(elems2).all(|(left, right)| left == right)
} else {
false