-
Notifications
You must be signed in to change notification settings - Fork 176
Case splitting fails with fancy types #336
Comments
I'm not sure where to look for a debug buffer, but |
You can get a debug buffer by running |
You can also just run |
Does that work when the error first shows up upon executing a command? |
Yeah debug just displays GHC/cabal version info and such. |
@acowley Does you bug also happen when pattern matching on a GADT? Maybe the functions I'm calling from the |
@serras looks like some |
I have just hit this in https://phabricator.haskell.org/D157, it is a Bool but initialised to an error value in the parser, which means that all You need to be careful not to evaluate |
Thank you @david-christiansen! It's a different error in the first file I tried:
And another file in the same project doesn't exhibit that error in the same way. So it's more FFI trickiness in my case. |
Glad I saw this, need to sort it out in the dev GHC On Thu, Aug 21, 2014 at 9:14 PM, Anthony Cowley notifications@github.com
|
The code that is concerned with the error is: getSrcSpanTypeForFnSplit :: GhcMonad m => G.ModSummary -> Int -> Int -> m (Maybe SplitInfo)
getSrcSpanTypeForFnSplit modSum lineNo colNo = do
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]
case varPat of
Nothing -> return Nothing
Just varPat' -> do
varT <- Gap.getType tcm varPat' -- Finally we get the type of the var
case varT of
Just varT' ->
let (L matchL (G.Match _ _ (G.GRHSs rhsLs _))) = match
in return $ Just (SplitInfo (getPatternVarName varPat') matchL varT' (map G.getLoc rhsLs) )
_ -> return Nothing In particular, it seems that the error happends in the call to instance HasType (LPat Id) where
getType _ (G.L spn pat) = return $ Just (spn, hsPatType pat) As you can see, I have called the type checker, so it seems to me that everything should be initialized correctly if I've reached that point, including the renamer. I have found a related bug from |
I am having a look now |
I think the problem arises from match:_ = listifyParsedSpans pms (lineNo, colNo) :: [Gap.GLMatch] in I put a pull request in recently but @nominolo has not reacted to it yet, see DanielG/ghc-syb#7 I will see if |
@alanz Thanks for taking care and fixig it. Do you know any reference that I could look at to understand what was going on more clearly? All this |
The primary references to SYB are here http://research.microsoft.com/en-us/um/people/simonpj/papers/hmap/ The key thing to it all is how a generic query happens, (which is from -- | Make a generic query;
-- start from a type-specific case;
-- return a constant otherwise
--
mkQ :: ( Typeable a
, Typeable b
)
=> r
-> (b -> r)
-> a
-> r
(r `mkQ` br) a = case cast a of
Just b -> br b
Nothing -> r which makes use of the type safe cast from Data.Data -- | The type-safe cast operation
cast :: forall a b. (Typeable a, Typeable b) => a -> Maybe b
cast x = if typeRep (Proxy :: Proxy a) == typeRep (Proxy :: Proxy b)
then Just $ unsafeCoerce x
else Nothing In other words it makes use of the metadata provided by the fact that a given In a similar fashion traversals are defined which can apply the generic query to all the immediate subterms of a given data item. The problem comes with the GHC AST which does things like data HsWithBndrs thing
= HsWB { hswb_cts :: thing -- Main payload (type or list of types)
, hswb_kvs :: [Name] -- Kind vars
, hswb_tvs :: [Name] -- Type vars
}
deriving (Data, Typeable)
mkHsWithBndrs :: thing -> HsWithBndrs thing
mkHsWithBndrs x = HsWB { hswb_cts = x, hswb_kvs = panic "mkHsTyWithBndrs:kvs"
, hswb_tvs = panic "mkHsTyWithBndrs:tvs" } So that instead of having the expected So the Unfortunately the original did not cover all of the panic situations, and GHC 7.8.3 brought in some more. Hence your problem. |
This is in version 5.0.1 of both the Emacs and Haskell bits. If I load the following file:
and then attempt to case split, I get the following message in the debug buffer:
The List equivalent works fine. I'm mostly used to
idris-mode
, so I may be doing something wrong here.The text was updated successfully, but these errors were encountered: