-Wambiguous-fields raised on field selectors of same type

Viewed 66

I just updated a project to GHC 9.2.4 and some modules raise the ambiguous-fields warning.
Reading about -XDuplicateRecordFields, I understand it is necessary to disambiguate same field names in different types when used as selectors.

But this code:

import Data.Aeson

customDefaultOptions :: Options
customDefaultOptions = defaultOptions {omitNothingFields = True}

newtypeOptions :: Options
newtypeOptions = customDefaultOptions {unwrapUnaryRecords = True}

Also raises it:

    The record update customDefaultOptions
                        {unwrapUnaryRecords = True} with type Options is ambiguous.
    This will not be supported by -XDuplicateRecordFields in future releases of GHC.
   |
 7 | newtypeOptions = customDefaultOptions {unwrapUnaryRecords = True}
   |                                        ^^^^^^^^^^^^^^^^^^^^^^^^^

Yet, customDefaultOptions is of type Options, like defaultOptions, where is the ambiguity?

1 Answers

Thanks to K. A. Buhr, I found that openapi3 exposes a very similar structure.

Prefixing field with its module name disambiguate it:

import qualified Data.Aeson as Aeson

newtypeOptions :: Options
newtypeOptions = customDefaultOptions {Aeson.unwrapUnaryRecords = True}
Related