Просмотр исходного кода

Avoid dereferencing a disengaged optional (#865)

Geoff Romer 4 лет назад
Родитель
Сommit
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());