
#9711: Confusing errors when compiling text-1.2.0.0 ----------------------------------+--------------------------------------- Reporter: asvyazin | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 Keywords: | Operating System: MacOS X Architecture: x86_64 (amd64) | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: ----------------------------------+--------------------------------------- I was trying to install text-1.2.0.0 on my system (Mac OS X 10.7.5 Lion) through cabal (cabal-install-1.20.0.3, cabal-1.20.0.2) and got some compile errors: [29 of 43] Compiling Data.Text.IO ( Data/Text/IO.hs, dist/build/Data/Text/IO.o ) Data/Text/IO.hs:236:29: The last statement in a 'do' block must be an expression n1 <- writeCharBuf raw n '\r' writeCharBuf raw n1 '\n' >>= inner s' Data/Text/IO.hs:237:49: Not in scope: ‘n1’ Perhaps you meant one of these: ‘n’ (line 230), ‘s1’ (line 228) Let's see what we have at 236 line of Data/Text/IO.hs: {{{#!hs writeBlocksCRLF :: Handle -> Buffer CharBufElem -> Stream Char -> IO () writeBlocksCRLF h buf0 (Stream next0 s0 _len) = outer s0 buf0 where outer s1 Buffer{bufRaw=raw, bufSize=len} = inner s1 (0::Int) where inner !s !n = case next0 s of Done -> commit n False{-no flush-} True{-release-} >> return () Skip s' -> inner s' n Yield x s' | n + 1 >= len -> commit n True{-needs flush-} False >>= outer s | x == '\n' -> do n1 <- writeCharBuf raw n '\r' -- 236 line is here!!! writeCharBuf raw n1 '\n' >>= inner s' | otherwise -> writeCharBuf raw n x >>= inner s' commit = commitBuffer h raw len }}} Seems legit… And if I rewrite this two lines as {{{#!hs | x == '\n' -> do n1 <- writeCharBuf raw n '\r'; writeCharBuf raw n1 '\n' >>= inner s' }}} then ghc compiles them fine. Even more interesting - if I rewrite this lines as {{{#!hs | x == '\n' -> do n1 <- writeCharBuf raw n '\r' writeCharBuf raw n1 '\n' >>= inner s' }}} then it compiles them too! Again, with context, look carefully: {{{#!hs Yield x s' | n + 1 >= len -> commit n True{-needs flush-} False >>= outer s | x == '\n' -> do n1 <- writeCharBuf raw n '\r' writeCharBuf raw n1 '\n' >>= inner s' | otherwise -> writeCharBuf raw n x >>= inner s' }}} doesn't work. {{{#!hs Yield x s' | n + 1 >= len -> commit n True{-needs flush-} False >>= outer s | x == '\n' -> do n1 <- writeCharBuf raw n '\r' writeCharBuf raw n1 '\n' >>= inner s' | otherwise -> writeCharBuf raw n x >>= inner s' }}} works! Weird… P.S. GHC version 7.8.3, installed through homebrew -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9711 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler