| 665 | #[test] |
| 666 | #[cfg_attr(miri, ignore)] |
| 667 | fn table_grow_func_subtyping() { |
| 668 | let engine = Engine::default(); |
| 669 | let mut store = Store::new(&engine, ()); |
| 670 | |
| 671 | let (a_ty, a, b_ty, b, c_ty, c) = dummy_funcs_and_subtypes(&mut store); |
| 672 | |
| 673 | for (table_ty, a_expected, b_expected, c_expected) in [ |
| 674 | // a <: a, b </: a, c </: a |
| 675 | (a_ty, true, false, false), |
| 676 | // a <: b, b <: b, c </: a |
| 677 | (b_ty, true, true, false), |
| 678 | // a <: c, b <: c, c <: c |
| 679 | (c_ty, true, true, true), |
| 680 | ] { |
| 681 | let table = Table::new( |
| 682 | &mut store, |
| 683 | TableType::new(RefType::new(true, table_ty.clone().into()), 3, None), |
| 684 | Ref::Func(None), |
| 685 | ) |
| 686 | .unwrap(); |
| 687 | |
| 688 | for (val, expected) in [(a, a_expected), (b, b_expected), (c, c_expected)] { |
| 689 | let orig_size = table.size(&store); |
| 690 | |
| 691 | match table.grow(&mut store, 10, val.into()) { |
| 692 | Ok(_) if expected => {} |
| 693 | Ok(_) => panic!("should have got type mismatch, but didn't"), |
| 694 | Err(e) if !expected => assert!(e.to_string().contains("type mismatch")), |
| 695 | Err(e) => panic!("should have done table grow, but got error: {e:?}"), |
| 696 | } |
| 697 | |
| 698 | if expected { |
| 699 | let new_size = table.size(&store); |
| 700 | assert_eq!(new_size, orig_size + 10); |
| 701 | for i in orig_size..new_size { |
| 702 | assert!(table.get(&mut store, i).expect("in bounds").is_non_null()); |
| 703 | } |
| 704 | } |
| 705 | } |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | #[test] |
| 710 | #[cfg_attr(miri, ignore)] |