Skip to content

Commit

Permalink
Test that local bindings are not inlined during desugaring
Browse files Browse the repository at this point in the history
  • Loading branch information
facundominguez committed Jan 29, 2024
1 parent 1ce20d7 commit 65d9104
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions liquidhaskell-boot/ghc-api-tests/GhcApiTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ testTree =
, testCase "caseDesugaring" testCaseDesugaring
, testCase "numericLiteralDesugaring" testNumLitDesugaring
, testCase "dollarDesugaring" testDollarDesugaring
, testCase "localBindingsDesugaring" testLocalBindingsDesugaring
]

-- Tests that Liquid.GHC.API.Extra.apiComments can retrieve the comments in
Expand Down Expand Up @@ -196,6 +197,32 @@ testDollarDesugaring = do
fail $ unlines $
"Unexpected desugaring:" : map showPprQualified coreProgram

-- | Test that local bindings are preserved.
testLocalBindingsDesugaring :: IO ()
testLocalBindingsDesugaring = do
let inputSource = unlines
[ "module LocalBindingsDesugaring where"
, "f :: ()"
, "f = z"
, " where"
, " z = ()"
]

fBind (GHC.NonRec b _e) =
occNameString (GHC.occName b) == "f"
fBind _ = False

isExpectedDesugaring p = case find fBind p of
Just (GHC.NonRec _ (Let (GHC.NonRec b _) _))
-> occNameString (GHC.occName b) == "z"
_ -> False

coreProgram <- compileToCore "LocalBindingsDesugaring" inputSource
unless (isExpectedDesugaring coreProgram) $
fail $ unlines $
"Unexpected desugaring:" : map showPprQualified coreProgram


compileToCore :: String -> String -> IO [GHC.CoreBind]
compileToCore modName inputSource = do
now <- getCurrentTime
Expand Down

0 comments on commit 65d9104

Please sign in to comment.