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

Avoid dereferencing a disengaged optional (#865)

Geoff Romer пре 4 година
родитељ
комит
52b09f099b
1 измењених фајлова са 3 додато и 1 уклоњено
  1. 3 1
      executable_semantics/interpreter/type_checker.cpp

+ 3 - 1
executable_semantics/interpreter/type_checker.cpp

@@ -992,7 +992,9 @@ auto TypeChecker::TypeCheckFunDef(FunctionDefinition* f, TypeEnv types,
                              &return_type_context);
     body_stmt = res.stmt;
     // Save the return type in case it changed.
-    return_type = *return_type_context.deduced_return_type();
+    if (return_type_context.deduced_return_type().has_value()) {
+      return_type = *return_type_context.deduced_return_type();
+    }
   }
   auto body = CheckOrEnsureReturn(body_stmt, f->is_omitted_return_type(),
                                   f->source_loc());