Skip to content

Commit 1f85cf3

Browse files
committed
Added elif fix in semantic and llvm so it passes the tests
1 parent 4ef6d68 commit 1f85cf3

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

llvm/ast.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1889,13 +1889,16 @@ class IfStmt : public Stmt
18891889
branches.push_back(then_block->check_return_case());
18901890

18911891
for(IfStmt* i : elifs) {
1892+
i->isElif = true;
18921893
branches.push_back(i->check_return_case());
18931894
}
18941895

18951896
if(else_block) {
18961897
branches.push_back(else_block->check_return_case());
18971898
} else {
1898-
branches.push_back(ReturnInfo(NO_RETURN, false, false));
1899+
if(!isElif) {
1900+
branches.push_back(ReturnInfo(NO_RETURN, false, false));
1901+
}
18991902
}
19001903

19011904
return combine_if(branches);
@@ -1993,6 +1996,7 @@ class IfStmt : public Stmt
19931996
Block *then_block;
19941997
std::vector<IfStmt *> elifs;
19951998
Block *else_block;
1999+
bool isElif = false;
19962000
};
19972001

19982002
class LoopStmt : public Stmt

semantic/ast.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,7 @@ class IfStmt : public Stmt
10931093

10941094
for (IfStmt *i : elifs)
10951095
{
1096+
i->isElif = true;
10961097
branches.push_back(i->check_return_case());
10971098
}
10981099

@@ -1102,7 +1103,9 @@ class IfStmt : public Stmt
11021103
}
11031104
else
11041105
{
1105-
branches.push_back(ReturnInfo(NO_RETURN, false, false));
1106+
if(!isElif) {
1107+
branches.push_back(ReturnInfo(NO_RETURN, false, false));
1108+
}
11061109
}
11071110

11081111
return combine_if(branches);
@@ -1113,6 +1116,7 @@ class IfStmt : public Stmt
11131116
Block *then_block;
11141117
std::vector<IfStmt *> elifs;
11151118
Block *else_block;
1119+
bool isElif = false;
11161120
};
11171121

11181122
class LoopStmt : public Stmt

0 commit comments

Comments
 (0)