From fb0c0b63bfa2cf6baecb5d270a1b8d4e78531819 Mon Sep 17 00:00:00 2001 From: Geoff Romer Date: Tue, 27 Jul 2021 11:14:10 -0700 Subject: [PATCH] Fix `match` bug when no `case` matches (#677) --- executable_semantics/interpreter/interpreter.cpp | 2 +- executable_semantics/test_list.bzl | 1 + executable_semantics/testdata/no_match.carbon | 12 ++++++++++++ executable_semantics/testdata/no_match.golden | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 executable_semantics/testdata/no_match.carbon create mode 100644 executable_semantics/testdata/no_match.golden diff --git a/executable_semantics/interpreter/interpreter.cpp b/executable_semantics/interpreter/interpreter.cpp index b6ec23ef63c1..244b23df7030 100644 --- a/executable_semantics/interpreter/interpreter.cpp +++ b/executable_semantics/interpreter/interpreter.cpp @@ -854,7 +854,7 @@ void StepStmt() { clause_num = (act->pos - 1) / 2; if (clause_num == static_cast(stmt->GetMatch().clauses->size())) { - frame->todo.Pop(2); + frame->todo.Pop(1); } } } diff --git a/executable_semantics/test_list.bzl b/executable_semantics/test_list.bzl index 84136a9def3b..cc4989e374ee 100644 --- a/executable_semantics/test_list.bzl +++ b/executable_semantics/test_list.bzl @@ -59,6 +59,7 @@ TEST_LIST = [ "match_placeholder", "match_type", "next", + "no_match", "pattern_init", "pattern_variable_fail", "placeholder_variable", diff --git a/executable_semantics/testdata/no_match.carbon b/executable_semantics/testdata/no_match.carbon new file mode 100644 index 000000000000..fc9b2bc4b431 --- /dev/null +++ b/executable_semantics/testdata/no_match.carbon @@ -0,0 +1,12 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +fn main() -> Int { + var x: Int = 0; + match (x) { + case 1 => + return 1; + } + return 0; +} diff --git a/executable_semantics/testdata/no_match.golden b/executable_semantics/testdata/no_match.golden new file mode 100644 index 000000000000..2db2755da426 --- /dev/null +++ b/executable_semantics/testdata/no_match.golden @@ -0,0 +1 @@ +result: 0