-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f7c49e5
commit c085855
Showing
4 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
message-index/messages/GHC-87139/illegalDerivingStrategy/after/IllegalDerivingStrategy.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{-# LANGUAGE DerivingStrategies #-} | ||
module IllegalDerivingStrategy where | ||
|
||
newtype Year = MkYear Int | ||
deriving newtype Show |
4 changes: 4 additions & 0 deletions
4
message-index/messages/GHC-87139/illegalDerivingStrategy/before/IllegalDerivingStrategy.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module IllegalDerivingStrategy where | ||
|
||
newtype Year = MkYear Int | ||
deriving newtype Show |
27 changes: 27 additions & 0 deletions
27
message-index/messages/GHC-87139/illegalDerivingStrategy/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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). |