From 0944820dbab5e738540cb1ebaf77251dcaa108f0 Mon Sep 17 00:00:00 2001 From: Alan Zimmerman Date: Sat, 23 Aug 2014 14:06:26 +0200 Subject: [PATCH] CaseSplit panic sorted. closes https://github.com/kazu-yamamoto/ghc-mod/issues/336 --- Language/Haskell/GhcMod/CaseSplit.hs | 4 ++-- Language/Haskell/GhcMod/Gap.hs | 3 +++ test/CaseSplitSpec.hs | 19 +++++++------------ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/Language/Haskell/GhcMod/CaseSplit.hs b/Language/Haskell/GhcMod/CaseSplit.hs index f3da01a..4d5a2ff 100644 --- a/Language/Haskell/GhcMod/CaseSplit.hs +++ b/Language/Haskell/GhcMod/CaseSplit.hs @@ -69,10 +69,10 @@ getSrcSpanTypeForSplit modSum lineNo colNo = do -- Information for a function case split getSrcSpanTypeForFnSplit :: GhcMonad m => G.ModSummary -> Int -> Int -> m (Maybe SplitInfo) getSrcSpanTypeForFnSplit modSum lineNo colNo = do - p@ParsedModule{pm_parsed_source = pms} <- G.parseModule modSum + p@ParsedModule{pm_parsed_source = _pms} <- G.parseModule modSum tcm@TypecheckedModule{tm_typechecked_source = tcs} <- G.typecheckModule p let varPat = find isPatternVar $ listifySpans tcs (lineNo, colNo) :: Maybe (LPat Id) - match:_ = listifyParsedSpans pms (lineNo, colNo) :: [Gap.GLMatch] + match:_ = listifySpans tcs (lineNo, colNo) :: [Gap.GLMatchI] case varPat of Nothing -> return Nothing Just varPat' -> do diff --git a/Language/Haskell/GhcMod/Gap.hs b/Language/Haskell/GhcMod/Gap.hs index 2db9972..fbbadd0 100644 --- a/Language/Haskell/GhcMod/Gap.hs +++ b/Language/Haskell/GhcMod/Gap.hs @@ -37,6 +37,7 @@ module Language.Haskell.GhcMod.Gap ( , benchmarkTargets , toModuleString , GLMatch + , GLMatchI , getClass , occName , setFlags @@ -437,8 +438,10 @@ toModuleString mn = fromFilePath $ M.toFilePath mn #if __GLASGOW_HASKELL__ >= 708 type GLMatch = LMatch RdrName (LHsExpr RdrName) +type GLMatchI = LMatch Id (LHsExpr Id) #else type GLMatch = LMatch RdrName +type GLMatchI = LMatch Id #endif getClass :: [LInstDecl Name] -> Maybe (Name, SrcSpan) diff --git a/test/CaseSplitSpec.hs b/test/CaseSplitSpec.hs index 4dd1d41..700cc68 100644 --- a/test/CaseSplitSpec.hs +++ b/test/CaseSplitSpec.hs @@ -1,25 +1,20 @@ -{-# LANGUAGE CPP #-} module CaseSplitSpec where -import Control.Applicative ((<$>)) -import Data.List (isPrefixOf) import Language.Haskell.GhcMod -#if __GLASGOW_HASKELL__ < 706 -import System.Environment.Executable (getExecutablePath) -#else -import System.Environment (getExecutablePath) -#endif -import System.Exit -import System.FilePath -import System.Process import Test.Hspec import TestUtils import Dir +main :: IO () +main = do + hspec spec + spec :: Spec spec = do describe "case split" $ do it "does not blow up on HsWithBndrs panic" $ do withDirectory_ "test/data/case-split" $ do res <- runD $ splits "Vect.hs" 24 10 - res `shouldBe` "9 5 11 40 \"Int -> a -> a -> a\"\n7 1 11 40 \"Int -> Integer\"\n" + res `shouldBe` "24 1 24 30"++ + " \"mlAppend Nil y = _mlAppend_body\NUL"++ + "mlAppend (Cons x1 x2) y = _mlAppend_body\"\n"