Skip to content

Commit

Permalink
Handle selecting from maybe types with .just?/.nothing?
Browse files Browse the repository at this point in the history
Reviewed By: malanka

Differential Revision: D59368949

fbshipit-source-id: b602d49e4a85ee5417d5460da2f58e3d63d434f2
  • Loading branch information
Simon Marlow authored and facebook-github-bot committed Jul 9, 2024
1 parent ee31f0e commit 806b567
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions glean/db/Glean/Query/Typecheck.hs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ fieldSelect src ty pat fieldName sum = do
| otherwise -> err $
"expression is a union type, use '." <> pretty fieldName <>
"?' not '." <> pretty fieldName <> "'"
MaybeTy elemTy ->
fieldSelect src (lowerMaybe elemTy) pat fieldName sum
_ -> err $ "expression is not a " <> if sum then "union type" else "record"

convertType
Expand Down
2 changes: 1 addition & 1 deletion glean/test/lib/TestData.hs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ mkTestFacts first second = do
, Glean.Test.kitchenSink_array_of_string = ["abba", "baba"]
, Glean.Test.kitchenSink_named_sum_ = Glean.Test.Sum_wed True
, Glean.Test.kitchenSink_named_record_ = rec
, Glean.Test.kitchenSink_maybe_ = Nothing
, Glean.Test.kitchenSink_maybe_ = Just def
}

-- also make a small variant of kitchenSink2Term0
Expand Down
5 changes: 5 additions & 0 deletions glean/test/tests/Angle/AngleTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,11 @@ angleDotTest = dbTestCase $ \env repo -> do
"X.sum_.c?.string_ where glean.test.Predicate X"
assertEqual "dot record.sum.record" ["abba", "acca"] r

-- maybe
r <- runQuery_ env repo $ angleData @Text
"X.string_ where (X : glean.test.Predicate).maybe_.just?"
assertEqual "dot maybe" ["abba", "acca"] r

-- error: field not found
r <- try $ runQuery env repo $ angleData @Text
"X.notfound where glean.test.Predicate X"
Expand Down

0 comments on commit 806b567

Please sign in to comment.