Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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
15 changes: 8 additions & 7 deletions 15 checker/src/main/java/dev/cel/checker/ExprChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -778,13 +778,14 @@ private TypeProvider.FieldType getFieldType(
} else {
// Proto message was added as a variable to the environment but the descriptor was not
// provided
env.reportError(
exprId,
position,
"Message type resolution failure while referencing field '%s'. Ensure that the descriptor"
+ " for type '%s' was added to the environment",
fieldName,
typeName);
String errorMessage =
String.format("Message type resolution failure while referencing field '%s'.", fieldName);
if (type.kind().equals(CelKind.STRUCT)) {
errorMessage +=
String.format(
" Ensure that the descriptor for type '%s' was added to the environment", typeName);
}
env.reportError(exprId, position, errorMessage, fieldName, typeName);
}
return ERROR;
}
Expand Down
28 changes: 28 additions & 0 deletions 28 checker/src/test/java/dev/cel/checker/ExprCheckerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,22 @@ public void messageFieldSelect() throws Exception {
runTest();
}

@Test
public void messageCreationError() throws Exception {
declareVariable("x", CelProtoTypes.INT64);
source = "x{foo: 1}";
runTest();

declareVariable("y", CelProtoTypes.create(CelProtoTypes.INT64));
source = "y{foo: 1}";
runTest();

declareVariable(
"z", CelProtoTypes.create(CelProtoTypes.createMessage("msg_without_descriptor")));
source = "z{foo: 1}";
runTest();
}

@Test
public void messageFieldSelectError() throws Exception {
declareVariable("x", createMessage("cel.expr.conformance.proto3.TestAllTypes"));
Expand Down Expand Up @@ -396,6 +412,18 @@ public void flexibleTypeAdaption() throws Exception {
runTest();
}

@Test
public void userFunctionOverlappingOverloadsError() throws Exception {
declareFunction(
"func",
memberOverload(
"overlapping_overload_1", ImmutableList.of(CelProtoTypes.INT64), CelProtoTypes.INT64),
memberOverload(
"overlapping_overload_2", ImmutableList.of(CelProtoTypes.INT64), CelProtoTypes.INT64));
source = "func(1)";
runTest();
}

// Json Types
// ==========

Expand Down
41 changes: 41 additions & 0 deletions 41 checker/src/test/resources/messageCreationError.baseline
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Source: x{foo: 1}
declare x {
value int
}
=====>
ERROR: test_location:1:2: 'int' is not a type
| x{foo: 1}
| .^
ERROR: test_location:1:6: Message type resolution failure while referencing field 'foo'.
| x{foo: 1}
| .....^

Source: y{foo: 1}
declare x {
value int
}
declare y {
value type(int)
}
=====>
ERROR: test_location:1:2: 'int' is not a message type
| y{foo: 1}
| .^
ERROR: test_location:1:6: Message type resolution failure while referencing field 'foo'.
| y{foo: 1}
| .....^

Source: z{foo: 1}
declare x {
value int
}
declare y {
value type(int)
}
declare z {
value type(msg_without_descriptor)
}
=====>
ERROR: test_location:1:6: Message type resolution failure while referencing field 'foo'. Ensure that the descriptor for type 'msg_without_descriptor' was added to the environment
| z{foo: 1}
| .....^
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Source: func(1)
declare func {
function overlapping_overload_1 int.() -> int
function overlapping_overload_2 int.() -> int
}
=====>
ERROR: test_location:1:1: overlapping overload for name 'func' (type '(int) -> int' cannot be distinguished from '(int) -> int')
| func(1)
| ^
Morty Proxy This is a proxified and sanitized view of the page, visit original site.