Skip to content

Commit

Permalink
fix(ast): removed lambda void return type check
Browse files Browse the repository at this point in the history
The LambdaExpr class will now not fail if a lambda with void return
type is provided
  • Loading branch information
diegomarquezp committed Jul 28, 2022
1 parent 5005f01 commit 51e49c4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 51e49c4

Please sign in to comment.