diff --git a/src/main/java/com/google/api/generator/engine/ast/LambdaExpr.java b/src/main/java/com/google/api/generator/engine/ast/LambdaExpr.java index dde9989825..2b8c1b6f44 100644 --- a/src/main/java/com/google/api/generator/engine/ast/LambdaExpr.java +++ b/src/main/java/com/google/api/generator/engine/ast/LambdaExpr.java @@ -67,9 +67,6 @@ public Builder setReturnExpr(Expr expr) { public LambdaExpr build() { LambdaExpr lambdaExpr = autoBuild(); - Preconditions.checkState( - !lambdaExpr.returnExpr().expr().type().equals(TypeNode.VOID), - "Lambdas cannot return void-typed expressions."); // Must be a declaration. lambdaExpr.arguments().stream() .forEach( diff --git a/src/test/java/com/google/api/generator/engine/ast/LambdaExprTest.java b/src/test/java/com/google/api/generator/engine/ast/LambdaExprTest.java index 8011d1a89e..1d1d5d685c 100644 --- a/src/test/java/com/google/api/generator/engine/ast/LambdaExprTest.java +++ b/src/test/java/com/google/api/generator/engine/ast/LambdaExprTest.java @@ -85,17 +85,15 @@ public void validLambdaExpr_withBody() { } @Test - public void invalidLambdaExpr_returnsVoid() { - assertThrows( - IllegalStateException.class, - () -> - LambdaExpr.builder() - .setReturnExpr( - MethodInvocationExpr.builder() - .setMethodName("foo") - .setReturnType(TypeNode.VOID) - .build()) - .build()); + public void validLambdaExpr_returnsVoid() { + LambdaExpr voidLambda = LambdaExpr.builder() + .setReturnExpr( + MethodInvocationExpr.builder() + .setMethodName("foo") + .setReturnType(TypeNode.VOID) + .build()) + .build(); + assertEquals(TypeNode.VOID, voidLambda.returnExpr().type()); } @Test