Skip to content
Merged
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
14 changes: 12 additions & 2 deletions verifier/src/main/java/dev/cel/verifier/CelZ3StructTranslator.java
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,14 @@ private Expr<?> getDefaultValueForType(CelType type) {
if (type.equals(SimpleType.DURATION)) {
return typeSystem.wrapDuration(ctx.mkInt(0));
}
// An unset google.protobuf.Value field reads as null.
if (type.equals(SimpleType.DYN)) {
return typeSystem.mkNull();
}
// An unset google.protobuf.Any field can't be unpacked.
if (type.equals(SimpleType.ANY)) {
return typeSystem.mkError();
}
if (type instanceof ListType) {
if (emptyListCache == null) {
emptyListCache = typeSystem.mkListRefConst(EMPTY_LIST_PREFIX);
Expand Down Expand Up @@ -514,8 +522,10 @@ TranslatedValue translateSelect(CelExpr celExpr, CelAbstractSyntaxTree ast) {
.addCase(isMap, mapAcc.presence)
.build(ctx.mkFalse());

Expr<?> defaultVal = getDefaultValueForType(extractAstTypeOrDefault(ast, exprId));
Expr<?> msgRead = ctx.mkITE(msgAcc.presence, msgAcc.value, defaultVal);
// TODO: Unsound: an unset field reads as an unknown, which can make a
// satisfiable
// expression look unsatisfiable. Its default depends on the message's runtime type.
Expr<?> msgRead = ctx.mkITE(msgAcc.presence, msgAcc.value, typeSystem.mkUnknown());
Expr<?> mapRead = ctx.mkITE(mapAcc.presence, mapAcc.value, typeSystem.mkError());

valueResult =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ private enum IsSatisfiableTestCase {
CROSS_NUMERIC_EQUALITY_INT_DYN_EXACT("1 == request", "request = 1"),
MACRO_LIMIT("dyn_list.all(x, x == 1)", "Satisfying input:"),
STRUCT_FIELD_MISSING_APPROXIMATE_SATISFIABLE("dyn_var.unknown_field", "dyn_var = "),
// An unset google.protobuf.Value field reads as null.
UNSET_VALUE_FIELD("TestAllTypes{}.single_value == null"),
MAP_INDEX_SATISFIABLE("string_int_map['alice'] > 0", "\"alice\": [1-9]\\d*"),
MAP_SIZE_GREATER_THAN_ONE_WITH_KEY(
"string_int_map.size() > 1 && string_int_map['foo'] == 42",
Expand Down Expand Up @@ -2303,6 +2305,8 @@ public void verifyEquivalence_inconclusive(

private enum EquivalenceTestCase {
STRUCT_UNSET_TIMESTAMP_DEFAULT("TestAllTypes{}.single_timestamp", "timestamp(0)"),
// Both are errors.
STRUCT_UNSET_ANY_DEFAULT("TestAllTypes{}.single_any == null", "1 / 0 == 1"),
TRUNCATION_STRICT_PROPAGATION_EQUIVALENT(
"size(int_list) == 6 ? size(int_list.filter(x, x > 2)) : 0",
"size(int_list) == 6 ? size(int_list.filter(y, y > 2)) : 0"),
Expand Down
Loading