[GHC] #8570: In a pattern binding:ghc: panic! (the 'impossible' happened): Bogus selector Id

GHC ghc-devs at haskell.org
Thu Nov 28 14:36:16 UTC 2013


#8570: In a pattern binding:ghc: panic! (the 'impossible' happened): Bogus
selector Id
----------------------------------+---------------------------------------
       Reporter:  rzetterberg     |             Owner:
           Type:  bug             |            Status:  new
       Priority:  normal          |         Milestone:
      Component:  Compiler        |           Version:  7.6.3
       Keywords:                  |  Operating System:  Linux
   Architecture:  x86_64 (amd64)  |   Type of failure:  Compile-time crash
     Difficulty:  Unknown         |         Test Case:
     Blocked By:                  |          Blocking:
Related Tickets:                  |
----------------------------------+---------------------------------------
 Hello,

 This is my first bug report for GHC. I encountered a type error when
 compiling my program that said to report the error as a bug here. I tried
 searching for similar bugs, but could not find any bugs with the same
 problem.

 I'm sorry in advance if I have misunderstood anything or if there indeed
 are any duplicates of this problem!

 '''The error output'''

 {{{
 src/app/Templates/Pages.hs:214:17:
     Constructor `Image' does not have field `filepath'
     In the pattern: Image {filepath = fp}
     In a pattern binding: Image {filepath = fp} = logo
     In an equation for `renderLogo':
         renderLogo (Design {mlogo = (Just logo)})
           = H.a ! A.href "/" ! A.class_ "navbar-brand"
             $ H.img ! A.src (toValue fp)
           where
               Image {filepath = fp} = logo

 src/app/Templates/Pages.hs:214:34:
     Couldn't match expected type `Field' with actual type `Image'
     In the expression: logo
     In a pattern binding:ghc: panic! (the 'impossible' happened)
   (GHC version 7.6.3 for x86_64-unknown-linux):
         Bogus selector Id

 Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug
 }}}

 '''When/why does this happen?'''

 I encountered this problem when I accidentally imported a field in a data
 named "Image" from module A, and imported the constructor of a different
 data structure from a different module also named "Image".

 I guess the type error itself is valid since it doesn't make sense to do
 what I did, but the way GHC handles this corner case internally is the
 source of the panic.

 Here are my imports:

 {{{
 import Data.Image (Image(filepath))
 import Data.Form (Field(..), FieldResult(..))
 }}}

 Data.Image contains the data structure Image, whereas Data.Form contains
 the data structure Field which has a constructor named Image.

 Here is the the data structure in Data.Image:

 {{{
 data Image = Image
     { id :: Integer
     , categoryId :: Integer
     , name :: String
     , filepath :: String
     , createdAt :: LocalTimestamp
     } deriving (Show)
 }}}

 And here is the data structure in Data.Form:

 {{{
 data Field
     = Password   Name Label
     | Text       Name Label Value
     | Email      Name Label Value
     | InlineArea Name Label Html
     | Hidden     Name Value
     | Image      Name Label
     | Select     Name Label [SelectItem] SelectedId
     | CheckBox   Name Label Selected
 }}}

 And here is the line I use the filepath field in my template file:

 {{{
     where Image{filepath = fp} = logo
 }}}

 '''Can this GHC panic be avoided?'''

 Yes, by specifically importing from the same module. Like so:

 {{{
 import Data.Image (Image(Image, filepath)
 import Data.Form (Field(InlineArea), FieldResult(..))
 }}}


 ----

 If there is anything more I can do to help, just let me know!

 Thank you
 Richard Zetterberg

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


More information about the ghc-tickets mailing list