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 committed Aug 2, 2022
1 parent 27a8aa2 commit 317eff6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
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
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 317eff6

Please sign in to comment.