Skip to content

deriving: infer DatatypeContexts from data constructors, not type constructor

Ryan Scott requested to merge wip/T20501 into master

Previously, derived instances that use deriving clauses would infer DatatypeContexts by using tyConStupidTheta. But this sometimes causes redundant constraints to be included in the derived instance contexts, as the constraints that appear in the tyConStupidTheta may not actually appear in the types of the data constructors (i.e., the dataConStupidThetas). For instance, in data Show a => T a = MkT deriving Eq, the type of MkT does not require Show, so the derived Eq instance should not require Show either. This patch makes it so with some small tweaks to inferConstraintsStock.

Fixes #20501 (closed).

Merge request reports