Skip to content

Ensure `type data` declarations don't exist at the term level

Ryan Scott requested to merge wip/T22948 into master

This MR is a collection of closely related patches that prevent type data data constructors from sneaking into the term level:

Don't generate datacon wrappers for type data declarations

Data constructor wrappers only make sense for value-level data constructors, but data constructors for type data declarations only exist at the type level. This patch does the following:

  • The criteria in GHC.Types.Id.Make.mkDataConRep for whether a data constructor receives a wrapper now consider whether or not its parent data type was declared with type data, omitting a wrapper if this is the case.

  • Now that type data data constructors no longer receive wrappers, there is a spot of code in refineDefaultAlt that panics when it encounters a value headed by a type data type constructor. I've fixed this with a special case in refineDefaultAlt and expanded Note [Refine DEFAULT case alternatives] to explain why we do this.

Fixes #22948 (closed).

Treat type data declarations as empty when checking pattern-matching coverage

The data constructors for a type data declaration don't exist at the value level, so we don't want GHC to warn users to match on them.

Fixes #22964 (closed).

Disallow tagToEnum# on type data types

We don't want to allow users to conjure up values of a type data type using tagToEnum#, as these simply don't exist at the value level.

Edited by Ryan Scott

Merge request reports