From b7d7b7acd42cbe424afde3c8a5a59a0706445343 Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Fri, 12 May 2017 14:36:08 -0400 Subject: Haddock: Fix broken lazy IO in prologue reading (#615) We previously used withFile in conjunction with hGetContents. The list returned by the latter wasn't completely forced by the time we left the withFile block, meaning that we would try to read from a closed handle. --- haddock-api/src/Haddock.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'haddock-api') diff --git a/haddock-api/src/Haddock.hs b/haddock-api/src/Haddock.hs index 6af0874a..637ccf2b 100644 --- a/haddock-api/src/Haddock.hs +++ b/haddock-api/src/Haddock.hs @@ -540,9 +540,10 @@ getPrologue :: DynFlags -> [Flag] -> IO (Maybe (MDoc RdrName)) getPrologue dflags flags = case [filename | Flag_Prologue filename <- flags ] of [] -> return Nothing - [filename] -> withFile filename ReadMode $ \h -> do + [filename] -> do + h <- openFile filename ReadMode hSetEncoding h utf8 - str <- hGetContents h + str <- hGetContents h -- semi-closes the handle return . Just $! parseParas dflags str _ -> throwE "multiple -p/--prologue options" -- cgit v1.2.3