Skip to content

Commit 29d5f9a

Browse files
authored
Enable commented tests for references and enums in match expressions (#5755)
## Description This PR enables temporarily commented tests: - related to references that were commented out because of the bug described in #5692. - related to enums in `match` expressions that were commented out because of type inference issues that were fixed in #5643. ## Checklist - [x] I have linked to any relevant issues. - [ ] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers.
1 parent 98cdaac commit 29d5f9a

File tree

4 files changed

+55
-56
lines changed
  • test/src/e2e_vm_tests/test_programs/should_pass/language

4 files changed

+55
-56
lines changed

test/src/e2e_vm_tests/test_programs/should_pass/language/match_expressions_enums/src/main.sw

+26-30
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
script;
22

3-
// TODO: Add this test once numeric type inference in tuples is improved.
4-
// enum E {
5-
// F: u64,
6-
// G: (u64, u64),
7-
// H: (u64, u64, u64),
8-
// }
3+
enum E {
4+
F: u64,
5+
G: (u64, u64),
6+
H: (u64, u64, u64),
7+
}
98

109
struct S {
1110
x: u64,
@@ -16,8 +15,7 @@ struct S {
1615
enum X {
1716
Y: u64,
1817
Z: bool,
19-
// TODO: Add this test once numeric type inference in tuples is improved.
20-
// K: E,
18+
K: E,
2119
S: S,
2220
}
2321

@@ -26,8 +24,7 @@ fn match_me(me: X) -> u64 {
2624
X::Y(10) | X::Y(20) | X::Y(30) => { 102030 },
2725
X::Y(hi) => { hi },
2826
X::Z(false) => { 1000 },
29-
// TODO: Add this test once numeric type inference in tuples is improved.
30-
// X::K(E::F(a) | E::G((101, x)) | E::H((202, 303, x))) => x,
27+
X::K(E::F(x) | E::G((101, x)) | E::H((202, 303, x))) => x,
3128
X::S(S {x: a, y: 102, z: 103}) | X::S(S {x: 201, y: a, z: 203}) | X::S(S {x: 301, y: 302, z: a}) => a,
3229
X::S(_) => 8888,
3330
_ => { 9999 },
@@ -50,26 +47,25 @@ fn main() -> u64 {
5047
let x = match_me(X::Z(false));
5148
assert (x == 1000);
5249

53-
// TODO: Add this test once numeric type inference in tuples is improved.
54-
// let x = match_me(X::K(E::F(42)));
55-
//
56-
// assert (x == 42);
57-
//
58-
// let x = match_me(X::K(E::G((101, 42))));
59-
//
60-
// assert (x == 42);
61-
//
62-
// let x = match_me(X::K(E::H((202, 303, 42))));
63-
//
64-
// assert (x == 42);
65-
//
66-
// let x = match_me(X::K(E::G((202, 42))));
67-
//
68-
// assert (x == 9999);
69-
//
70-
// let x = match_me(X::K(E::H((303, 303, 42))));
71-
//
72-
// assert (x == 9999);
50+
let x = match_me(X::K(E::F(42)));
51+
52+
assert (x == 42);
53+
54+
let x = match_me(X::K(E::G((101, 42))));
55+
56+
assert (x == 42);
57+
58+
let x = match_me(X::K(E::H((202, 303, 42))));
59+
60+
assert (x == 42);
61+
62+
let x = match_me(X::K(E::G((202, 42))));
63+
64+
assert (x == 9999);
65+
66+
let x = match_me(X::K(E::H((303, 303, 42))));
67+
68+
assert (x == 9999);
7369

7470
let x = match_me(X::S(S { x:42, y: 102, z:103 }));
7571
assert (x == 42);

test/src/e2e_vm_tests/test_programs/should_pass/language/match_expressions_or/src/lib_enum.sw

+14-16
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ fn match_option(o: Option<Enum>) -> u64 {
2121
| Enum::B((111, 111, 111))
2222
| Enum::B((222, 222, 222))
2323
) => 111111222222,
24-
// TODO: Add this case once the issue with type inference in tuples is solved.
25-
//Some(
26-
// Enum::A((x, 11, 11))
27-
// | Enum::A((22, x, 22))
28-
// | Enum::B((111, 111, x))
29-
// | Enum::B((x, 222, 222))
30-
//) => x,
24+
Some(
25+
Enum::A((x, 11, 11))
26+
| Enum::A((22, x, 22))
27+
| Enum::B((111, 111, x))
28+
| Enum::B((x, 222, 222))
29+
) => x,
3130
None => 5555,
3231
_ => 9999,
3332
}
@@ -64,18 +63,17 @@ pub fn test() -> u64 {
6463
let x = match_option(Some(Enum::B((222, 222, 222))));
6564
assert(x == 111111222222);
6665

67-
// TODO: Add this case once the issue with type inference in tuples is solved.
68-
//let x = match_option(Some(Enum::A((42, 11, 11))));
69-
//assert(x == 42);
66+
let x = match_option(Some(Enum::A((42, 11, 11))));
67+
assert(x == 42);
7068

71-
//let x = match_option(Some(Enum::A((22, 42, 22))));
72-
//assert(x == 42);
69+
let x = match_option(Some(Enum::A((22, 42, 22))));
70+
assert(x == 42);
7371

74-
//let x = match_option(Some(Enum::B((111, 111, 42))));
75-
//assert(x == 42);
72+
let x = match_option(Some(Enum::B((111, 111, 42))));
73+
assert(x == 42);
7674

77-
//let x = match_option(Some(Enum::B((42, 222, 222))));
78-
//assert(x == 42);
75+
let x = match_option(Some(Enum::B((42, 222, 222))));
76+
assert(x == 42);
7977

8078
let x = match_option(None);
8179
assert(x == 5555);

test/src/e2e_vm_tests/test_programs/should_pass/language/match_expressions_or/src/lib_tuple.sw

+10-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ library;
33
fn match_tuple(t: (u64, u64)) -> u64 {
44
match t {
55
(11, 111) | (22, 222) | (33, 333) => 112233,
6-
// TODO: Add these tests once the issue with type inference is solved.
7-
// Mismatched types. expected: (u64, u64) found: (numeric, {unknown}).
8-
// (11, x) | (22, x) | (33, x) => x,
6+
(11, x) | (22, x) | (33, x) => x,
97
_ => {
108
return 9999;
119
},
@@ -22,6 +20,15 @@ pub fn test() -> u64 {
2220
let x = match_tuple((33, 333));
2321
assert(x == 112233);
2422

23+
let x = match_tuple((11, 42));
24+
assert(x == 42);
25+
26+
let x = match_tuple((22, 42));
27+
assert(x == 42);
28+
29+
let x = match_tuple((33, 42));
30+
assert(x == 42);
31+
2532
let x = match_tuple((0, 0));
2633
assert(x == 9999);
2734

test/src/e2e_vm_tests/test_programs/should_pass/language/references/referencing_local_vars_and_values/src/main.sw

+5-7
Original file line numberDiff line numberDiff line change
@@ -124,21 +124,19 @@ fn reference_zero_sized_local_var_and_value<T>()
124124
{
125125
assert(__size_of::<T>() == 0);
126126

127-
// TODO-IG: Return test for mutable references once https://github.com/FuelLabs/sway/issues/5692 is fixed.
128-
// let mut x = T::new();
129-
let x = T::new();
127+
let mut x = T::new();
130128

131129
let r_x_1 = &x;
132130
let r_x_2 = &x;
133131
let r_val = &T::new();
134132

135133
assert_references_zero_size(r_x_1, r_x_2, r_val, x);
136134

137-
// let r_x_1 = &mut x;
138-
// let r_x_2 = &mut x;
139-
// let r_val = &mut T::new();
135+
let r_x_1 = &mut x;
136+
let r_x_2 = &mut x;
137+
let r_val = &mut T::new();
140138

141-
// assert_references_zero_size(r_x_1, r_x_2, r_val, x);
139+
assert_references_zero_size(r_x_1, r_x_2, r_val, x);
142140
}
143141

144142
fn assert_references_zero_size<T>(r_x_1: &T, r_x_2: &T, r_val: &T, x: T) where T: Eq + New + ZeroSize {

0 commit comments

Comments
 (0)