Skip to content

Warn on derived Newtype & Generic instances for exported types with non-exported constructors #3707

@hdgarrood

Description

@hdgarrood

Defining a Newtype or Generic instance for a data type effectively means that anyone who can see the type can also see its constructor(s). Therefore, I don't think there is ever a good reason to export a data type without its constructors if that data type has Newtype or Generic instances. Additionally, I suspect that when exported types have these instances without exported constructors, it's usually accidental, and the author doesn't realise that they are effectively making the constructors public by providing these instances.

I'd suggest having the compiler emit warnings for data types where all of the following are true:

  • The data type is exported
  • Not all of the constructors are exported
  • The type has a derived Newtype or Generic instance

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions