
#13644: overloaded name used in record pattern matching leads to panic! (the 'impossible' happened) in ghc -------------------------------------+------------------------------------- Reporter: pjljvdlaar | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: #13840, #13973, | Differential Rev(s): #14087 | Wiki Page: | -------------------------------------+------------------------------------- Comment (by sighingnow): Maybe we should throw a type error when pattern name mismatch, rather than just panic. Use the case from #13973 as an example, {{{#!haskell -- Record.hs module Record (Record(..)) where data Record = Record { field1 :: Int, field2 :: Int } -- Test.hs module Test (foo) where import qualified Record as Rec field2 :: () field2 = () foo :: Rec.Record -> Int foo Rec.Record{field2 = field2} = field2 }}} In function `translateConPatVec` (in `compiler/deSugar/Check.hs`, during the desugar pass), we can't know whether the pattern label comes from the record fields, or just another ordinary symbol. When pattern name lookup (`lookup name zipped`) fails, **we could reach a conclusion** that `name` must not be one of the record fields. Then the compiler can throw an error like {{{ Test.hs:11:16: error: Record field not in scope: ‘field2’ Perhaps you meant one of these: ‘Rec.field1’ (imported from Record), ‘Rec.field2’ (imported from Record), }}} (Noticing that `Record field not in scope` has point out that the missing item is a record field label, rather than other ordinary variable, without causing any confusion.) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13644#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler