Skip to content

Commit

Permalink
Changed ExpectReturnOnAllPaths() to treat continuation, run and await…
Browse files Browse the repository at this point in the history
… as missing returns (#1258)

Fixes #1257
  • Loading branch information
pk19604014 authored May 17, 2022
1 parent fb0e8fa commit 88be617
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
compilation_unit {
declarations {
class_declaration {
members {
function {
return_term {
kind: Auto
}
body {
statements {
await_statement {
}
}
}
}
}
}
}
}
1 change: 0 additions & 1 deletion explorer/interpreter/type_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1978,7 +1978,6 @@ auto TypeChecker::ExpectReturnOnAllPaths(
case StatementKind::Continuation:
case StatementKind::Run:
case StatementKind::Await:
return Success();
case StatementKind::Assign:
case StatementKind::ExpressionStatement:
case StatementKind::While:
Expand Down
Original file line number Diff line number Diff line change
@@ -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} %{explorer} %s 2>&1 | \
// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes=false %s
// RUN: %{not} %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
// AUTOUPDATE: %{explorer} %s

package ExplorerTest api;

fn Main() -> i32 {
var x: i32 = 0;
__continuation k {
x = x + 1;
// CHECK: COMPILATION ERROR: {{.*}}/explorer/testdata/experimental_continuation/fail_return_in_continuation.carbon:[[@LINE+1]]: return is not within a function body
return x;
}
}

0 comments on commit 88be617

Please sign in to comment.