[GHC] #14307: NamedFieldPuns should allow "ambiguous" field names
GHC
ghc-devs at haskell.org
Tue Oct 3 13:35:55 UTC 2017
#14307: NamedFieldPuns should allow "ambiguous" field names
-------------------------------------+-------------------------------------
Reporter: mgsloan | Owner: (none)
Type: feature request | Status: new
Priority: low | Milestone:
Component: Compiler | Version: 8.2.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by simonpj):
> This seems like poor behavior, because since a particular constructor is
used, it is unambiguous which field is intended.
Yes, but you need `-XDisambiguateRecordFields` for that
([http://downloads.haskell.org/~ghc/master/users-guide/glasgow_exts.html
#record-field-disambiguation user manual entry]). Haskell 2010 specifies
that the code is should be rejected. So I think GHC is behaving right
here.
Incidentally, `-XDisambiguateRecordFields` is also implied by
`-XDuplicateRecordFields`.
> I actually encountered this issue in a bit of a different usecase.
Yes, here's the code
{{{
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
module T14307 where
data A = A { field :: Int }
data B = B { field :: Int }
f (C { field }) = field
}}}
You get two errors with 8.2
{{{
T14307.hs:10:4: error: Not in scope: data constructor ‘C’
|
10 | f (C { field }) = field
| ^
T14307.hs:10:8: error:
Ambiguous occurrence ‘field’
It could refer to either the field ‘field’,
defined at T14307.hs:7:14
or the field ‘field’, defined at T14307.hs:6:14
|
10 | f (C { field }) = field
| ^^^^^
}}}
I think your point is that you'd like the second to be suppressed. I see
the point. Are you also ok with getting just one error message from
{{{
f (A { fld = x }) = ...
}}}
namely `'A' is not in scope`; but no `fld is not in scope`? That is: if
the data constructor is not in scope, suppress out-of-scope or ambiguity
messages for the fields. I think that'd be fine.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14307#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list