1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//! > Test let-else statement
//! > test_runner_name
test_expr_semantics(expect_diagnostics: false)
//! > function_body
let a = MyEnum::A(9);
//! > expr_code
{
let x = ();
let MyEnum::A(x) = a else {
// The `x` below is the outer `x` (unit type).
return x;
};
x
}
//! > module_code
enum MyEnum {
A: felt252,
B: felt252,
}
//! > expected_semantics
Block(
ExprBlock {
statements: [
Let(
StatementLet {
pattern: Variable(
x,
),
expr: Tuple(
ExprTuple {
items: [],
ty: (),
},
),
else_clause: None,
},
),
Let(
StatementLet {
pattern: EnumVariant(
PatternEnumVariant {
variant: MyEnum::A,
inner_pattern: Some(
Variable(
x,
),
),
ty: test::MyEnum,
},
),
expr: Var(
LocalVarId(test::a),
),
else_clause: Some(
Block(
ExprBlock {
statements: [
Return(
StatementReturn {
expr_option: Some(
Var(
LocalVarId(test::x),
),
),
},
),
],
tail: None,
ty: core::never,
},
),
),
},
),
],
tail: Some(
Var(
LocalVarId(test::x),
),
),
ty: core::felt252,
},
)
//! > expected_diagnostics
//! > ==========================================================================
//! > Test let-else statement with empty else block
//! > test_runner_name
test_expr_semantics(expect_diagnostics: true)
//! > function_body
let a = MyEnum::A(9);
//! > expr_code
{
let MyEnum::A(x) = a else {};
x
}
//! > module_code
enum MyEnum {
A: felt252,
B: felt252,
}
//! > expected_semantics
Block(
ExprBlock {
statements: [
Let(
StatementLet {
pattern: EnumVariant(
PatternEnumVariant {
variant: MyEnum::A,
inner_pattern: Some(
Variable(
x,
),
),
ty: test::MyEnum,
},
),
expr: Var(
LocalVarId(test::a),
),
else_clause: Some(
Block(
ExprBlock {
statements: [],
tail: None,
ty: (),
},
),
),
},
),
],
tail: Some(
Var(
LocalVarId(test::x),
),
),
ty: core::felt252,
},
)
//! > expected_diagnostics
error[E2195]: `else` clause of `let...else` must exit the scope. Consider using `return`, `continue`, ...
--> lib.cairo:7:31
let MyEnum::A(x) = a else {};
^^