File tree Expand file tree Collapse file tree 4 files changed +48
-0
lines changed
message-index/messages/GHC-87139 Expand file tree Collapse file tree 4 files changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ {-# LANGUAGE DerivingStrategies #-}
2
+ module IllegalDerivingStrategy where
3
+
4
+ newtype Year = MkYear Int
5
+ deriving newtype Show
Original file line number Diff line number Diff line change
1
+ module IllegalDerivingStrategy where
2
+
3
+ newtype Year = MkYear Int
4
+ deriving newtype Show
Original file line number Diff line number Diff line change
1
+ ---
2
+ title : Illegal deriving strategy on newtype
3
+ ---
4
+
5
+ In this example, there is a deriving clause instructing GHC
6
+ to derive a ` Show ` instance for the newtype ` Year ` .
7
+
8
+ There are (at least) two different ways to derive such a ` Show `
9
+ instance. The ` stock ` strategy is the standard generic way of
10
+ deriving ` Show ` instances for datatypes. The ` newtype ` strategy
11
+ is available for ` newtype ` s and simply uses the existing instance
12
+ of the underlying type, in this case ` Int ` .
13
+
14
+ The difference in the current example is that the ` stock ` -derived
15
+ ` show ` includes the constructor name, the ` newtype ` -derived does
16
+ not.
17
+
18
+ If multiple strategies are available, GHC chooses a default. In
19
+ the case of ` deriving ` for classes for which ` stock ` -deriving is
20
+ available, such as ` Show ` , ` stock ` is the default. If you want to
21
+ be explicit about this or explicitly deviate from the default,
22
+ you can specify a strategy explicitly.
23
+
24
+ This, however, requires the ` DerivingStrategies ` language extension
25
+ to be enabled, and if it is not, you will get an error. The fix in
26
+ this case is to enable the language extension, for example via a
27
+ compiler pragma.
Original file line number Diff line number Diff line change
1
+ ---
2
+ title : Illegal deriving strategy
3
+ summary : Use of a deriving strategy without enabling the corresponding language extension
4
+ severity : error
5
+ introduced : 9.8.1
6
+ ---
7
+
8
+ This error occurs if the syntax for specifying a deriving strategy
9
+ is being used without having the corresponding language extension enabled.
10
+
11
+ The fix is usually to either enable the language extension, or to remove
12
+ the deriving strategy (if it happens to match the default).
You can’t perform that action at this time.
0 commit comments