Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions common/values/optional_value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ OpaqueValue GenericOptionalValueClone(
cel::Value* absl_nonnull result =
::new (arena->AllocateAligned(sizeof(cel::Value), alignof(cel::Value)))
cel::Value(content.To<OptionalValueContent>().value->Clone(arena));
if (!ArenaTraits<>::trivially_destructible(result)) {
if (!ArenaTraits<>::trivially_destructible(*result)) {
arena->OwnDestructor(result);
}
return common_internal::MakeOptionalValue(
Expand Down Expand Up @@ -395,7 +395,7 @@ OptionalValue OptionalValue::Of(cel::Value value,
cel::Value* absl_nonnull result = ::new (
arena->AllocateAligned(sizeof(cel::Value), alignof(cel::Value)))
cel::Value(std::move(value));
if (!ArenaTraits<>::trivially_destructible(result)) {
if (!ArenaTraits<>::trivially_destructible(*result)) {
arena->OwnDestructor(result);
}
return OptionalValue(&optional_value_dispatcher,
Expand Down
1 change: 1 addition & 0 deletions runtime/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ cc_test(
":activation",
":constant_folding",
":function_adapter",
":optional_types",
":reference_resolver",
":regex_precompilation",
":runtime",
Expand Down
10 changes: 10 additions & 0 deletions runtime/memory_safety_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "runtime/activation.h"
#include "runtime/constant_folding.h"
#include "runtime/function_adapter.h"
#include "runtime/optional_types.h"
#include "runtime/reference_resolver.h"
#include "runtime/regex_precompilation.h"
#include "runtime/runtime.h"
Expand Down Expand Up @@ -174,6 +175,7 @@ absl::StatusOr<std::unique_ptr<Runtime>> ConfigureRuntimeImpl(
if (resolve_references) {
CEL_RETURN_IF_ERROR(EnableReferenceResolver(
runtime_builder, ReferenceResolverEnabled::kAlways));
CEL_RETURN_IF_ERROR(extensions::EnableOptionalTypes(runtime_builder));
}
if (evaluation_options == Options::kFoldConstants) {
CEL_RETURN_IF_ERROR(extensions::EnableConstantFolding(runtime_builder));
Expand Down Expand Up @@ -315,6 +317,14 @@ INSTANTIATE_TEST_SUITE_P(
{{"condition", BoolValue(false)}},
test::StringValueIs("long_right_hand_string_0123456789"),
},
{"optional_of_long_const_string",
"condition ? optional.of('lhs_short') : "
"optional.of('long_right_hand_string_0123456789')",
{{"condition", BoolValue(false)}},
test::OptionalValueIs(
test::StringValueIs("long_right_hand_string_0123456789")),
// optional.of is a namespaced function.
/*enable_reference_resolver=*/true},
{
"computed_string",
"(condition ? 'a.b' : 'b.c') + '.d.e.f'",
Expand Down