diff --git a/executable_semantics/BUILD b/executable_semantics/BUILD index 72e6a3a4834e..05f4806210ae 100644 --- a/executable_semantics/BUILD +++ b/executable_semantics/BUILD @@ -90,6 +90,7 @@ EXAMPLES = [ "match_type", "next", "pattern_init", + "pattern_variable_fail", "record1", "struct1", "struct2", diff --git a/executable_semantics/interpreter/typecheck.cpp b/executable_semantics/interpreter/typecheck.cpp index ad89ea9d442c..d9880d9dc26f 100644 --- a/executable_semantics/interpreter/typecheck.cpp +++ b/executable_semantics/interpreter/typecheck.cpp @@ -149,6 +149,7 @@ auto TypeCheckExp(Expression* e, TypeEnv* env, Env* ct_env, Value* expected, << ": compilation error, pattern variables are only allowed in " "pattern context" << std::endl; + exit(-1); } auto t = ToType(e->line_num, InterpExp(ct_env, e->u.pattern_variable.type)); diff --git a/executable_semantics/testdata/pattern_variable_fail.6c b/executable_semantics/testdata/pattern_variable_fail.6c new file mode 100644 index 000000000000..6abbf7b5838e --- /dev/null +++ b/executable_semantics/testdata/pattern_variable_fail.6c @@ -0,0 +1,8 @@ +// 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 { + Int : x; // error + return 1; +} diff --git a/executable_semantics/testdata/pattern_variable_fail.golden b/executable_semantics/testdata/pattern_variable_fail.golden new file mode 100644 index 000000000000..78b7f53f731d --- /dev/null +++ b/executable_semantics/testdata/pattern_variable_fail.golden @@ -0,0 +1,11 @@ +********** source program ********** +fn main () -> Int { +Int: x; +return 1; + +} +********** type checking ********** +--- step exp Int ---> +--- step exp Int ---> +2: compilation error, pattern variables are only allowed in pattern context +EXIT CODE: 255