Skip to content

Commit

Permalink
fix(ast): removed lambda void return type check (#1019)
Browse files Browse the repository at this point in the history
Fix for Issue #843. This pull request modifies allows the creation of lambda expressions that have void as return type. The main change was made in engine/ast/LambdaExpr.java
  • Loading branch information
diegomarquezp authored Aug 2, 2022
1 parent 7712d8c commit 9d792bc
Show file tree
Hide file tree
Showing 2 changed files with 10 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,16 @@ 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 9d792bc

Please sign in to comment.