Skip to content

Field imposters with DuplicateRecordFields and NamedFieldPuns.

There's a 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}
  1. 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}
Trac metadata
Trac field Value
Version 8.2.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related #13644 (closed)
Blocking
CC
Operating system
Architecture
Edited by Phil de Joux
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information