Skip to content

Commit

Permalink
Generic inference test
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed Jul 23, 2024
1 parent 157a82b commit e7e434e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions crates/rue-typing/src/comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,4 +368,32 @@ mod tests {
let rhs = db.alloc(Type::Pair(types.atom, types.atom));
assert_eq!(db.compare(lhs, rhs), Comparison::Assignable);
}

#[test]
fn test_generic_inference() {
let (mut db, types) = setup();

let generic = db.alloc(Type::Generic);

let mut stack = vec![HashMap::new()];

assert_eq!(
db.compare_with_generics(types.int, generic, &mut stack, true),
Comparison::Assignable
);

assert_eq!(stack.len(), 1);
assert_eq!(stack[0].get(&generic), Some(&types.int));

for infer in [true, false] {
assert_eq!(
db.compare_with_generics(types.bytes, generic, &mut stack, infer),
Comparison::Castable
);
assert_eq!(
db.compare_with_generics(types.any, generic, &mut stack, infer),
Comparison::Superset
);
}
}
}

0 comments on commit e7e434e

Please sign in to comment.