mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-25 20:50:12 +01:00
Additional test cases for returning from match (#897)
Requested during review of #882
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
// 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
|
||||
//
|
||||
// RUN: not executable_semantics %s 2>&1 | \
|
||||
// RUN: FileCheck --match-full-lines --allow-unused-prefixes=false %s
|
||||
// RUN: not executable_semantics --trace %s 2>&1 | \
|
||||
// RUN: FileCheck --match-full-lines --allow-unused-prefixes %s
|
||||
// AUTOUPDATE: executable_semantics %s
|
||||
// CHECK: COMPILATION ERROR: {{.*}}/executable_semantics/testdata/function/fail_match_no_return.carbon:17: control-flow reaches end of function that provides a `->` return type without reaching a return statement
|
||||
|
||||
package ExecutableSemanticsTest api;
|
||||
|
||||
fn main() -> i32 {
|
||||
var x: i32 = 0;
|
||||
match(0) {
|
||||
case 1 => { x = 1; }
|
||||
case _: auto => { x = 2; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// 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
|
||||
//
|
||||
// RUN: not executable_semantics %s 2>&1 | \
|
||||
// RUN: FileCheck --match-full-lines --allow-unused-prefixes=false %s
|
||||
// RUN: not executable_semantics --trace %s 2>&1 | \
|
||||
// RUN: FileCheck --match-full-lines --allow-unused-prefixes %s
|
||||
// AUTOUPDATE: executable_semantics %s
|
||||
// CHECK: COMPILATION ERROR: {{.*}}/executable_semantics/testdata/function/fail_match_partial_return.carbon:17: control-flow reaches end of function that provides a `->` return type without reaching a return statement
|
||||
|
||||
package ExecutableSemanticsTest api;
|
||||
|
||||
fn main() -> i32 {
|
||||
var x: i32 = 0;
|
||||
match (0) {
|
||||
case 1 => { x = 1; }
|
||||
case _: auto => { return 0; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user