[GHC] #14892: Field imposters with DuplicateRecordFields
GHC
ghc-devs at haskell.org
Mon Mar 5 17:09:44 UTC 2018
#14892: Field imposters with DuplicateRecordFields
-------------------------------------+-------------------------------------
Reporter: philderbeast | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.2.2
Keywords: | Operating System: MacOS X
Architecture: x86_64 | Type of failure: GHC accepts
(amd64) | invalid program
Test Case: | Blocked By:
Blocking: | Related Tickets: 13644
Differential Rev(s): | Wiki Page:
-------------------------------------+-------------------------------------
There's a [[https://github.com/BlockScope/ghc-panic-12158|test case]] for
this ghc panic. If I use `NamedFieldPuns` I wish this could more
delicately pick the right field. If my record use is qualified then please
restrict the set of candidate field names to use punned.
{{{
{-# LANGUAGE DuplicateRecordFields #-}
module Geodesy (X(..), Y(..)) where
data X a = X {x :: a}
data Y a = Y {x :: a}
}}}
{{{
{-# LANGUAGE NamedFieldPuns #-}
module GhcPanic12158 where
import qualified Geodesy as G (X(..))
import Geodesy (Y(..))
update :: G.X a -> G.X a
update G.X{x} = G.X{x = x}
}}}
{{{
> stack build
ghc-panic-translateConPatVec-lookup-0.1.0: build (lib)
Preprocessing library for ghc-panic-translateConPatVec-lookup-0.1.0..
Building library for ghc-panic-translateConPatVec-lookup-0.1.0..
[1 of 3] Compiling Geodesy
[2 of 3] Compiling GhcPanic12158
ghc: panic! (the 'impossible' happened)
(GHC version 8.2.2 for x86_64-apple-darwin):
translateConPatVec: lookup
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
}}}
There are some fixes;
1. Add DuplicateRecordFields.
{{{
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE DuplicateRecordFields #-}
module GhcPanic12158 where
import qualified Geodesy as G (X(..))
import Geodesy (Y(..))
update :: G.X a -> G.X a
update G.X{x} = G.X{x = x}
}}}
2. Use qualified field names.
{{{
{-# LANGUAGE NamedFieldPuns #-}
module GhcPanic12158 where
import qualified Geodesy as G (X(..))
import Geodesy (Y(..))
update :: G.X a -> G.X a
update G.X{G.x} = G.X{G.x = x}
}}}
Interestingly, if I don't import the record with the clashing field name
then GHC complains.
{{{
{-# LANGUAGE NamedFieldPuns #-}
module GhcPanic12158 where
import qualified Geodesy as G (X(..))
update :: G.X a -> G.X a
update G.X{x} = G.X{x = x}
}}}
{{{
> stack build
ghc-panic-translateConPatVec-lookup-0.1.0: unregistering
ghc-panic-translateConPatVec-lookup-0.1.0: build (lib)
Preprocessing library for ghc-panic-translateConPatVec-lookup-0.1.0..
Building library for ghc-panic-translateConPatVec-lookup-0.1.0..
[3 of 3] Compiling GhcPanic12158
/ghc-panic-12158/earth/library/GhcPanic12158.hs:8:12: error: Not in scope:
‘x’
|
8 | update G.X{x} = G.X{x = x}
| ^
/ghc-panic-12158/earth/library/GhcPanic12158.hs:8:21: error: Not in scope:
‘x’
|
8 | update G.X{x} = G.X{x = x}
}}}
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14892>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list