#7453: unsafe coerce without extensions
----------------------------------------+-----------------------------------
Reporter:  guest                        |          Owner:                       
  
    Type:  bug                          |         Status:  new                  
  
Priority:  normal                       |      Component:  Compiler (Type 
checker)
 Version:  7.6.1                        |       Keywords:                       
  
      Os:  Unknown/Multiple             |   Architecture:  Unknown/Multiple     
  
 Failure:  GHC accepts invalid program  |      Blockedby:                       
  
Blocking:                               |        Related:                       
  
----------------------------------------+-----------------------------------
 The following program implements an unsafe coerce and works on versions of
 GHC at least as far back as 7.0.3 but is fixed in HEAD. I'm reporting this
 because I don't know if it was fixed on purpose and might merit at least a
 fix to the 7.6.X branch if not the 7.4.X branch (due to its use in the
 platform)

 {{{
 newtype Id a = Id { runId :: a }

 -- Providing this type triggers a type-error
 -- cast :: a -> b
 cast v = runId z
   where
   z :: Id v
   z = aux
     where
     aux = Id v
 }}}

 Example usage:
 {{{
 *Main> map cast [97..107 :: Int] :: String
 "abcdefghijk"

 *Main> cast (Just True) :: String
 "\-1152921504589708267Segmentation fault: 11
 }}}

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7453>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to