Opened 9 years ago

Closed 9 years ago

#4891 closed bug (fixed)

dataConInfoPtrToName doesn't correctly resolve constructors with a trailing .

Reported by: TristanAllwood Owned by: igloo
Priority: high Milestone: 7.2.1
Component: Compiler Version: 6.12.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: T4891
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

I believe the parse helper in dataConInfoPtrToName in ghci/Linker.lhs doesn't correctly parse data constructors that feature a trailing . in the name.

Test case:

module X where

data X =  Int :-> Int
       |  Int :->. Int

The second constructor (:->.) will exhibit this bug.

Program to show the bug (in the same directory, needs ghc-paths from hackage):

{-# LANGUAGE BangPatterns #-}
module Main where

import ByteCodeLink
import CoreMonad
import Data.Array
import DataCon
import GHC
import HscTypes
import Linker
import RtClosureInspect
import GHC.Paths
import TcEnv
import Type
import TcRnMonad
import TcType
import Control.Applicative
import Name (getOccString)
import Unsafe.Coerce
import Control.Monad
import Data.Maybe
import Bag
import PrelNames (iNTERACTIVE)
import Outputable
import X

main :: IO ()
main = runGhc (Just libdir) $ do
  dflags' <- getSessionDynFlags 
  primPackages <- setSessionDynFlags dflags'
  dflags <- getSessionDynFlags
  defaultCleanupHandler dflags $ do
    target <- guessTarget "X.hs" Nothing
    setTargets [target]
    load LoadAllTargets

    () <- chaseConstructor (unsafeCoerce False)
    () <- chaseConstructor (unsafeCoerce [1,2,3])
    () <- chaseConstructor (unsafeCoerce (3 :-> 2))
    () <- chaseConstructor (unsafeCoerce (4 :->. 4))
    return ()

chaseConstructor :: (GhcMonad m) => HValue -> m ()
chaseConstructor !hv = do
  closure <- liftIO $ getClosureData hv
  case tipe closure  of
    Indirection _ -> chaseConstructor (ptrs closure ! 0)
    Constr -> do
      withSession $ \hscEnv -> liftIO $ initTcForLookup hscEnv $ do
        eDcname <- dataConInfoPtrToName (infoPtr closure)
        case eDcname of
          Left _       -> return ()
          Right dcName -> do
            liftIO $ putStrLn $ "Name: "      ++ showPpr dcName
            liftIO $ putStrLn $ "OccString: " ++ "'" ++ getOccString dcName ++ "'"
            dc <- tcLookupDataCon dcName
            liftIO $ putStrLn $ "DataCon: "   ++ showPpr dc
    _ -> return ()

initTcForLookup :: HscEnv -> TcM a -> IO a
initTcForLookup hsc_env = liftM (\(msg, mValue) -> fromMaybe (error . show . bagToList . snd $ msg) mValue) . initTc hsc_env HsSrcFile False iNTERACTIVE

Under 6.12.1, this outputs:

>./Main 
Name: GHC.Bool.False
OccString: 'False'
DataCon: GHC.Bool.False
Name: :
OccString: ':'
DataCon: :
Name: X.:->
OccString: ':->'
DataCon: X.:->
Name: X.:->.
OccString: ''
Main: [Failed to load interface for `X.:->':
  Use -v to see a list of the files searched for.]

Note in the last case it's trying to load the interface for :-> (not :->.), and the OccString hasn't correctly been resolved.

Change History (3)

comment:1 Changed 9 years ago by simonmar

Milestone: 7.0.3
Priority: normalhigh

comment:2 Changed 9 years ago by igloo

Owner: set to igloo

comment:3 Changed 9 years ago by igloo

Resolution: fixed
Status: newclosed
Test Case: T4891

Fixed by:

commit 9330f8d055e9e1113cecbf4e57b9f6a750fe0291
Author: Ian Lynagh <igloo@earth.li>
Date:   Sun Apr 3 15:23:38 2011 +0100

    Fix parsing constructors containing dots; fixes trac #4891

and test added.

Note: See TracTickets for help on using tickets.