From c085855e789d9abd313a4ce797333d8ad6edebfb Mon Sep 17 00:00:00 2001 From: Andres Loeh Date: Fri, 7 Jun 2024 17:37:21 +0200 Subject: [PATCH] Add explanation for GHC-87139. --- .../after/IllegalDerivingStrategy.hs | 5 ++++ .../before/IllegalDerivingStrategy.hs | 4 +++ .../illegalDerivingStrategy/index.md | 27 +++++++++++++++++++ message-index/messages/GHC-87139/index.md | 12 +++++++++ 4 files changed, 48 insertions(+) create mode 100644 message-index/messages/GHC-87139/illegalDerivingStrategy/after/IllegalDerivingStrategy.hs create mode 100644 message-index/messages/GHC-87139/illegalDerivingStrategy/before/IllegalDerivingStrategy.hs create mode 100644 message-index/messages/GHC-87139/illegalDerivingStrategy/index.md create mode 100644 message-index/messages/GHC-87139/index.md diff --git a/message-index/messages/GHC-87139/illegalDerivingStrategy/after/IllegalDerivingStrategy.hs b/message-index/messages/GHC-87139/illegalDerivingStrategy/after/IllegalDerivingStrategy.hs new file mode 100644 index 00000000..f974948d --- /dev/null +++ b/message-index/messages/GHC-87139/illegalDerivingStrategy/after/IllegalDerivingStrategy.hs @@ -0,0 +1,5 @@ +{-# LANGUAGE DerivingStrategies #-} +module IllegalDerivingStrategy where + +newtype Year = MkYear Int + deriving newtype Show diff --git a/message-index/messages/GHC-87139/illegalDerivingStrategy/before/IllegalDerivingStrategy.hs b/message-index/messages/GHC-87139/illegalDerivingStrategy/before/IllegalDerivingStrategy.hs new file mode 100644 index 00000000..4bc004bd --- /dev/null +++ b/message-index/messages/GHC-87139/illegalDerivingStrategy/before/IllegalDerivingStrategy.hs @@ -0,0 +1,4 @@ +module IllegalDerivingStrategy where + +newtype Year = MkYear Int + deriving newtype Show diff --git a/message-index/messages/GHC-87139/illegalDerivingStrategy/index.md b/message-index/messages/GHC-87139/illegalDerivingStrategy/index.md new file mode 100644 index 00000000..08cdb282 --- /dev/null +++ b/message-index/messages/GHC-87139/illegalDerivingStrategy/index.md @@ -0,0 +1,27 @@ +--- +title: Illegal deriving strategy on newtype +--- + +In this example, there is a deriving clause instructing GHC +to derive a `Show` instance for the newtype `Year`. + +There are (at least) two different ways to derive such a `Show` +instance. The `stock` strategy is the standard generic way of +deriving `Show` instances for datatypes. The `newtype` strategy +is available for `newtype`s and simply uses the existing instance +of the underlying type, in this case `Int`. + +The difference in the current example is that the `stock`-derived +`show` includes the constructor name, the `newtype`-derived does +not. + +If multiple strategies are available, GHC chooses a default. In +the case of `deriving` for classes for which `stock`-deriving is +available, such as `Show`, `stock` is the default. If you want to +be explicit about this or explicitly deviate from the default, +you can specify a strategy explicitly. + +This, however, requires the `DerivingStrategies` language extension +to be enabled, and if it is not, you will get an error. The fix in +this case is to enable the language extension, for example via a +compiler pragma. diff --git a/message-index/messages/GHC-87139/index.md b/message-index/messages/GHC-87139/index.md new file mode 100644 index 00000000..099fd4eb --- /dev/null +++ b/message-index/messages/GHC-87139/index.md @@ -0,0 +1,12 @@ +--- +title: Illegal deriving strategy +summary: Use of a deriving strategy without enabling the corresponding language extension +severity: error +introduced: 9.8.1 +--- + +This error occurs if the syntax for specifying a deriving strategy +is being used without having the corresponding language extension enabled. + +The fix is usually to either enable the language extension, or to remove +the deriving strategy (if it happens to match the default).