Skip to content

Commit

Permalink
Merge pull request #921 from getquill/fix-918
Browse files Browse the repository at this point in the history
fix nested option map
  • Loading branch information
fwbrasil authored Sep 24, 2017
2 parents e716688 + 1769a68 commit 1a52c2b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object FlattenOptionOperation extends StatelessTransformer {
case OptionMap(ast, alias, body) =>
apply(BetaReduction(body, alias -> ast))
case OptionForall(ast, alias, body) =>
val isEmpty = BinaryOperation(ast, EqualityOperator.`==`, NullValue)
val isEmpty = apply(BinaryOperation(ast, EqualityOperator.`==`, NullValue): Ast)
val exists = apply(BetaReduction(body, alias -> ast))
BinaryOperation(isEmpty, BooleanOperator.`||`, exists)
case OptionExists(ast, alias, body) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,24 @@ class FlattenOptionOperationSpec extends Spec {
BinaryOperation(Ident("o"), EqualityOperator.`!=`, Constant(1))
)
}

"map + forall" in {
val q = quote {
(o: Option[TestEntity]) => o.map(_.i).forall(i => i != 1)
}
FlattenOptionOperation(q.ast.body: Ast) mustEqual
BinaryOperation(
BinaryOperation(Property(Ident("o"), "i"), EqualityOperator.`==`, NullValue),
BooleanOperator.`||`,
BinaryOperation(Property(Ident("o"), "i"), EqualityOperator.`!=`, Constant(1))
)
}
"exists" in {
val q = quote {
(o: Option[Int]) => o.exists(i => i > 1)
}
FlattenOptionOperation(q.ast.body: Ast) mustEqual
BinaryOperation(Ident("o"), NumericOperator.`>`, Constant(1))
}

"contains" in {
val q = quote {
(o: Option[Int]) => o.contains(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ object VerifySqlQuery {
require(
invalid.isEmpty,
s"Found an `ON` table reference of a table that is not available: $invalid. " +
"The `ON` condition can only use tables defined through explicit joins.."
"The `ON` condition can only use tables defined through explicit joins."
)
nav
}
Expand Down

0 comments on commit 1a52c2b

Please sign in to comment.