Преглед изворни кода

Add continuation name to name resolution after processing continuation body (#1264)

Fixes #1263

This makes the continuation behave similar to this C++ lambda construct - auto f = []() { f(); }; which doesn't compile.
pk19604014 пре 4 година
родитељ
комит
45b18098ed

+ 22 - 0
explorer/fuzzing/fuzzer_corpus/3e9392fe2e7d549f249dff5f7e74dfb0ba6b912c.textproto

@@ -0,0 +1,22 @@
+compilation_unit {
+  declarations {
+    function {
+      body {
+        statements {
+          continuation {
+            body {
+              statements {
+                run {
+                  argument {
+                    identifier {
+                    }
+                  }
+                }
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+}

+ 4 - 4
explorer/interpreter/resolve_names.cpp

@@ -308,13 +308,13 @@ static auto ResolveNames(Statement& statement, StaticScope& enclosing_scope)
       break;
     }
     case StatementKind::Continuation: {
+      StaticScope continuation_scope;
+      continuation_scope.AddParent(&enclosing_scope);
       auto& continuation = cast<Continuation>(statement);
+      CARBON_RETURN_IF_ERROR(
+          ResolveNames(continuation.body(), continuation_scope));
       CARBON_RETURN_IF_ERROR(
           enclosing_scope.Add(continuation.name(), &continuation));
-      StaticScope continuation_scope;
-      continuation_scope.AddParent(&enclosing_scope);
-      CARBON_RETURN_IF_ERROR(ResolveNames(cast<Continuation>(statement).body(),
-                                          continuation_scope));
       break;
     }
     case StatementKind::Run: