Skip to content

Commit c364687

Browse files
committed
fix(sema): increase scope to match an explicit else
1 parent aef69a5 commit c364687

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

regression-tests/pure2-last-use.cpp2

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ issue_884: () = {
8888
}
8989
}
9090

91+
issue_884_2: () = {
92+
x := new<int>(0);
93+
if true { }
94+
{
95+
f_inout(x);
96+
}
97+
f_copy(x);
98+
}
99+
91100
issue_888: (copy r: std::string, copy size: int) = {
92101
// ...
93102
_ = r.size();

regression-tests/test-results/pure2-last-use.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class issue_857_2;
2020
class issue_857_3;
2121

2222

23-
#line 103 "pure2-last-use.cpp2"
23+
#line 112 "pure2-last-use.cpp2"
2424
class my_string;
2525

2626

@@ -91,12 +91,15 @@ class issue_857_3 {
9191
auto issue_884() -> void;
9292

9393
#line 91 "pure2-last-use.cpp2"
94+
auto issue_884_2() -> void;
95+
96+
#line 100 "pure2-last-use.cpp2"
9497
auto issue_888(std::string r, int size) -> void;
9598

96-
#line 97 "pure2-last-use.cpp2"
99+
#line 106 "pure2-last-use.cpp2"
97100
auto draw() -> void;
98101

99-
#line 103 "pure2-last-use.cpp2"
102+
#line 112 "pure2-last-use.cpp2"
100103
class my_string {
101104
public: std::string string;
102105
public: std::size_t size {CPP2_UFCS(size)(string)};
@@ -200,6 +203,15 @@ auto issue_884() -> void{
200203
}
201204
}
202205

206+
auto issue_884_2() -> void{
207+
auto x {cpp2_new<int>(0)};
208+
if (true) {}
209+
{
210+
f_inout(x);
211+
}
212+
f_copy(std::move(x));
213+
}
214+
203215
auto issue_888(std::string r, int size) -> void{
204216
// ...
205217
static_cast<void>(CPP2_UFCS_MOVE(size)(std::move(r)));
@@ -212,10 +224,10 @@ auto draw() -> void{
212224
static_cast<void>(CPP2_UFCS_MOVE(vertex)((std::move(pos))));
213225
}
214226

215-
#line 108 "pure2-last-use.cpp2"
227+
#line 117 "pure2-last-use.cpp2"
216228
auto main(int const argc_, char** argv_) -> int{
217229
auto const args = cpp2::make_args(argc_, argv_);
218-
#line 109 "pure2-last-use.cpp2"
230+
#line 118 "pure2-last-use.cpp2"
219231
issue_683(args);
220232
issue_847_2(std::vector<std::unique_ptr<int>>());
221233
}

source/sema.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1888,7 +1888,10 @@ class sema
18881888
active_selections.pop_back();
18891889
// Extend the scope of an implicit else branch
18901890
// to the closing brace that contains it.
1891-
if (s.false_branch->position() != source_position(0, 0)) {
1891+
if (s.false_branch->position() == source_position(0, 0)) {
1892+
++scope_depth;
1893+
}
1894+
else {
18921895
--scope_depth;
18931896
}
18941897
}

0 commit comments

Comments
 (0)