mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
fix interpreter's handling of optional else of if statement (#323)
This commit is contained in:
@@ -81,9 +81,7 @@ EXAMPLES = [
|
||||
"fun6_fail_type",
|
||||
"funptr1",
|
||||
"if1",
|
||||
# (Temporarily disabled pending
|
||||
# https://github.com/carbon-language/carbon-lang/issues/311)
|
||||
# "if2",
|
||||
"if2",
|
||||
"if3",
|
||||
"match_int_default",
|
||||
"match_int",
|
||||
|
||||
@@ -1177,12 +1177,14 @@ void HandleValue() {
|
||||
// -> { { then_stmt :: C, E, F } :: S, H}
|
||||
frame->todo.Pop(2);
|
||||
frame->todo.Push(MakeStmtAct(stmt->u.if_stmt.then_stmt));
|
||||
} else {
|
||||
} else if (stmt->u.if_stmt.else_stmt) {
|
||||
// { {false :: if ([]) then_stmt else else_stmt :: C, E, F} ::
|
||||
// S, H}
|
||||
// -> { { else_stmt :: C, E, F } :: S, H}
|
||||
frame->todo.Pop(2);
|
||||
frame->todo.Push(MakeStmtAct(stmt->u.if_stmt.else_stmt));
|
||||
} else {
|
||||
frame->todo.Pop(2);
|
||||
}
|
||||
break;
|
||||
case StatementKind::While:
|
||||
|
||||
+20
-2
@@ -136,8 +136,26 @@ env: main: fun<main>,
|
||||
else
|
||||
<1>(false,) --->
|
||||
{
|
||||
stack: main{<-1> :: return 0;<-1>} :: top{}
|
||||
stack: main{return 0;<-1>} :: top{}
|
||||
heap: fun<main>,
|
||||
env: main: fun<main>,
|
||||
}
|
||||
--- step stmt --->
|
||||
--- step stmt return 0; --->
|
||||
{
|
||||
stack: main{0<-1> :: return 0;<0>} :: top{}
|
||||
heap: fun<main>,
|
||||
env: main: fun<main>,
|
||||
}
|
||||
--- step exp 0 --->
|
||||
{
|
||||
stack: main{0<-1> :: return 0;<0>} :: top{}
|
||||
heap: fun<main>,
|
||||
env: main: fun<main>,
|
||||
}
|
||||
--- handle value 0 with return 0;<1>(0,) --->
|
||||
{
|
||||
stack: top{0<-1>}
|
||||
heap: fun<main>,
|
||||
env: main: fun<main>,
|
||||
}
|
||||
result: 0
|
||||
|
||||
Reference in New Issue
Block a user