DeriveGeneric gets a wrong infix constructor associativity when type is declared in a different module
Summary
For example, the operators (:|) (NonEmpty) and (:) (lists, []) are infixr 5, but their Generic.Rep say otherwise ('InfixI 'LeftAssociative 9) (see code block below for an illustration).
My most plausible hypothesis for the cause is that DeriveGeneric does not take precedence into account when the type lives in a different module from its Generic instance. Indeed, NonEmpty and [] have their Generic instances derived in GHC.Generic, whereas things looks fine if we declare a type with an infix constructor and derive Generic in the same module.
ghci> :kind! (Rep [Int])
(Rep [Int]) :: * -> *
= D1
('MetaData "[]" "GHC.Types" "ghc-prim" 'False)
(C1 ('MetaCons "[]" 'PrefixI 'False) U1
:+: C1
('MetaCons ":" ('InfixI 'LeftAssociative 9) 'False)
...)
ghci> :kind! (Rep (NonEmpty Int))
(Rep (NonEmpty Int)) :: * -> *
= D1
('MetaData "NonEmpty" "GHC.Base" "base" 'False)
(C1
('MetaCons ":|" ('InfixI 'LeftAssociative 9) 'False)
...)
Expected behavior
These two examples should read 'InfixI 'RightAssociative 5.
Environment
- GHC version used: 8.6, 8.8