Opened 3 years ago

Closed 3 years ago

#7256 closed bug (fixed)

Missing dataCast1 and dataCast2 methods in Data.Data instances

Reported by: dreixel Owned by:
Priority: normal Milestone: 7.8.1
Component: Compiler Version: 7.6.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description

Having a look at Data instances in module Data.Data, Ptr a and ForeignPtr a are missing a dataCast1 = gcast1 line. And Array a b seems to be missing the dataCast2 method.

Change History (8)

comment:1 Changed 3 years ago by simonpj

  • difficulty set to Unknown

Any chance of a patch? Sounds as if you know just what to do.

comment:2 Changed 3 years ago by dreixel

Yes, I'll take care of this, it's trivial.

comment:3 follow-up: Changed 3 years ago by dreixel

  • Status changed from new to infoneeded

Here's the fix:

diff --git a/Data/Data.hs b/Data/Data.hs
index 0a29668..cb2d894 100644
--- a/Data/Data.hs
+++ b/Data/Data.hs
@@ -1275,27 +1275,27 @@ instance (Data a, Data b, Data c, Data d, Data e, Data f
 
 ------------------------------------------------------------------------------
 
-instance Typeable a => Data (Ptr a) where
+instance (Data a, Typeable a) => Data (Ptr a) where
   toConstr _   = error "Data.Data.toConstr(Ptr)"
   gunfold _ _  = error "Data.Data.gunfold(Ptr)"
   dataTypeOf _ = mkNoRepType "GHC.Ptr.Ptr"
-
+  dataCast1 x  = gcast1 x
 
 ------------------------------------------------------------------------------
 
-instance Typeable a => Data (ForeignPtr a) where
+instance (Data a, Typeable a) => Data (ForeignPtr a) where
   toConstr _   = error "Data.Data.toConstr(ForeignPtr)"
   gunfold _ _  = error "Data.Data.gunfold(ForeignPtr)"
   dataTypeOf _ = mkNoRepType "GHC.ForeignPtr.ForeignPtr"
-
+  dataCast1 x  = gcast1 x
 
 ------------------------------------------------------------------------------
 -- The Data instance for Array preserves data abstraction at the cost of 
 -- inefficiency. We omit reflection services for the sake of data abstraction.
-instance (Typeable a, Data b, Ix a) => Data (Array a b)
+instance (Typeable a, Data a, Data b, Ix a) => Data (Array a b)
  where
   gfoldl f z a = z (listArray (bounds a)) `f` (elems a)
   toConstr _   = error "Data.Data.toConstr(Array)"
   gunfold _ _  = error "Data.Data.gunfold(Array)"
   dataTypeOf _ = mkNoRepType "Data.Array.Array"
-
+  dataCast2 x  = gcast2 x

Note however that this requires adding additional Data constraints to these instances; perhaps this is the reason why these methods were omitted in the first place. So fixing this might break client code that uses these instances. Nonetheless, they are required for the correct behavior of SYB's ext/1/2 functions.

Shall I go ahead and push the patch?

comment:4 Changed 3 years ago by igloo

  • Status changed from infoneeded to patch

comment:5 in reply to: ↑ 3 Changed 3 years ago by igloo

  • Milestone set to 7.8.1

Replying to dreixel:

Shall I go ahead and push the patch?

Probably worth asking on libraries@, to give people the chance to object.

comment:6 Changed 3 years ago by igloo

  • Owner dreixel deleted
  • Status changed from patch to new

Removing patch tag until libraries@ has given an opinion.

comment:7 Changed 3 years ago by dreixel

There was no opinion: http://permalink.gmane.org/gmane.comp.lang.haskell.libraries/18099

I was going to proceed and patch.

comment:8 Changed 3 years ago by igloo

  • Resolution set to fixed
  • Status changed from new to closed

Ah, great. I've applied it. Thanks!

Note: See TracTickets for help on using tickets.