Procházet zdrojové kódy

Changed ExpectReturnOnAllPaths() to treat continuation, run and await as missing returns (#1258)

Fixes #1257
pk19604014 před 4 roky
rodič
revize
88be617360

+ 19 - 0
explorer/fuzzing/fuzzer_corpus/770513d3093894a2df74c8efcb4d135f430f45b5.textproto

@@ -0,0 +1,19 @@
+compilation_unit {
+  declarations {
+    class_declaration {
+      members {
+        function {
+          return_term {
+            kind: Auto
+          }
+          body {
+            statements {
+              await_statement {
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+}

+ 0 - 1
explorer/interpreter/type_checker.cpp

@@ -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:

+ 20 - 0
explorer/testdata/experimental_continuation/fail_return_in_continuation.carbon

@@ -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;
+  }
+}