diff --git a/message-index/messages/GHC-10498/function-arguments/after/Lib.hs b/message-index/messages/GHC-10498/function-arguments/after/Lib.hs new file mode 100644 index 00000000..44a5fe7d --- /dev/null +++ b/message-index/messages/GHC-10498/function-arguments/after/Lib.hs @@ -0,0 +1,6 @@ +module Lib where + +areDifferent :: Eq a => a -> a -> Maybe (a, a) +areDifferent x y + | x == y = Nothing +areDifferent x y = Just (x, y) diff --git a/message-index/messages/GHC-10498/function-arguments/before/Lib.hs b/message-index/messages/GHC-10498/function-arguments/before/Lib.hs new file mode 100644 index 00000000..1ba98ff1 --- /dev/null +++ b/message-index/messages/GHC-10498/function-arguments/before/Lib.hs @@ -0,0 +1,5 @@ +module Lib where + +areDifferent :: a -> a -> Maybe (a, a) +areDifferent x x = Nothing +areDifferent x y = Just (x, y) diff --git a/message-index/messages/GHC-10498/function-arguments/index.md b/message-index/messages/GHC-10498/function-arguments/index.md new file mode 100644 index 00000000..52bdadb4 --- /dev/null +++ b/message-index/messages/GHC-10498/function-arguments/index.md @@ -0,0 +1,25 @@ +--- +title: Duplicate function arguments +--- + +``` +Lib.hs:4:14: error: [GHC-10498] + • Conflicting definitions for ‘x’ + Bound at: Lib.hs:4:14 + Lib.hs:4:16 + • In an equation for ‘areDifferent’ + | +4 | areDifferent x x = Nothing + | +``` + +*Advanced topic:* somewhat surprisingly, you are allowed +to duplicate arguments of type-level functions as in + +```haskell +{-# LANGUAGE DataKinds, TypeFamilies #-} +type family IsElem x xs where + IsElem _ '[] = 'False + IsElem x (x ': xs) = 'True + IsElem x (_ ': xs) = IsElem x xs +``` diff --git a/message-index/messages/GHC-10498/index.md b/message-index/messages/GHC-10498/index.md new file mode 100644 index 00000000..1dc0725e --- /dev/null +++ b/message-index/messages/GHC-10498/index.md @@ -0,0 +1,12 @@ +--- +title: Conflicting definitions +summary: The same entity has more than one definition +severity: error +introduced: 9.6.1 +--- + +GHC does not allow the same entity to have more than one +definitions. In some contexts it can figure out which one +supposed to shadow another: local definitions take +priority over global definitions, etc. Shadowing is just a warning, GHC-63397. However, if the definitions are on the same +level it becomes a fatal error. diff --git a/message-index/messages/GHC-10498/type-parameters/after/Lib.hs b/message-index/messages/GHC-10498/type-parameters/after/Lib.hs new file mode 100644 index 00000000..191ea5ce --- /dev/null +++ b/message-index/messages/GHC-10498/type-parameters/after/Lib.hs @@ -0,0 +1,3 @@ +module Lib where + +data Pair a = Pair a a diff --git a/message-index/messages/GHC-10498/type-parameters/before/Lib.hs b/message-index/messages/GHC-10498/type-parameters/before/Lib.hs new file mode 100644 index 00000000..da42c11f --- /dev/null +++ b/message-index/messages/GHC-10498/type-parameters/before/Lib.hs @@ -0,0 +1,3 @@ +module Lib where + +data Pair a a = Pair a a diff --git a/message-index/messages/GHC-10498/type-parameters/index.md b/message-index/messages/GHC-10498/type-parameters/index.md new file mode 100644 index 00000000..26684342 --- /dev/null +++ b/message-index/messages/GHC-10498/type-parameters/index.md @@ -0,0 +1,13 @@ +--- +title: Duplicate datatype parameters +--- + +``` +Lib.hs:3:11: error: [GHC-10498] + Conflicting definitions for ‘a’ + Bound at: Lib.hs:3:11 + Lib.hs:3:13 + | +3 | data Pair a a = Pair a a + | +``` diff --git a/message-index/messages/GHC-10498/typo/after/Lib.hs b/message-index/messages/GHC-10498/typo/after/Lib.hs new file mode 100644 index 00000000..6927dad4 --- /dev/null +++ b/message-index/messages/GHC-10498/typo/after/Lib.hs @@ -0,0 +1,7 @@ +module Lib where + +function :: Int -> Int +function 1 = 1 +function 2 = 2 +function 3 = 3 +function _ = 4 diff --git a/message-index/messages/GHC-10498/typo/before/Lib.hs b/message-index/messages/GHC-10498/typo/before/Lib.hs new file mode 100644 index 00000000..4e3a3ea3 --- /dev/null +++ b/message-index/messages/GHC-10498/typo/before/Lib.hs @@ -0,0 +1,7 @@ +module Lib where + +function :: Int -> Int +function 1 = 1 +function 2 = 2 +functlon 3 = 3 +function _ = 4 diff --git a/message-index/messages/GHC-10498/typo/index.md b/message-index/messages/GHC-10498/typo/index.md new file mode 100644 index 00000000..dd3054dc --- /dev/null +++ b/message-index/messages/GHC-10498/typo/index.md @@ -0,0 +1,18 @@ +--- +title: Just a typo +--- + +``` +Lib.hs:7:1: error: [GHC-29916] + Multiple declarations of ‘function’ + Declared at: Lib.hs:4:1 + Lib.hs:7:1 + | +7 | function _ = 4 + | +``` + +Because of a typo (`functlon` instead of `function`) +GHC parses the third equation as a definition of +`functlon` (without a type signature), while the fourth +equation becomes the second, conflicting definition of `function`. diff --git a/message-index/messages/GHC-10498/wildcards/after/Lib.hs b/message-index/messages/GHC-10498/wildcards/after/Lib.hs new file mode 100644 index 00000000..0320d9ba --- /dev/null +++ b/message-index/messages/GHC-10498/wildcards/after/Lib.hs @@ -0,0 +1,8 @@ +{-# LANGUAGE NamedFieldPuns #-} + +module Lib where + +data Foo = Foo { x :: Int, y :: Int } + +foo :: Foo -> Int -> Int +foo Foo{y} x = x + y diff --git a/message-index/messages/GHC-10498/wildcards/before/Lib.hs b/message-index/messages/GHC-10498/wildcards/before/Lib.hs new file mode 100644 index 00000000..4710ba86 --- /dev/null +++ b/message-index/messages/GHC-10498/wildcards/before/Lib.hs @@ -0,0 +1,8 @@ +{-# LANGUAGE RecordWildCards #-} + +module Lib where + +data Foo = Foo { x :: Int, y :: Int } + +foo :: Foo -> Int -> Int +foo Foo{..} x = x + y diff --git a/message-index/messages/GHC-10498/wildcards/index.md b/message-index/messages/GHC-10498/wildcards/index.md new file mode 100644 index 00000000..4365f25b --- /dev/null +++ b/message-index/messages/GHC-10498/wildcards/index.md @@ -0,0 +1,17 @@ +--- +title: Implicit duplication because of `RecordWildCards` +--- + +``` +Lib.hs:8:9: error: [GHC-10498] + • Conflicting definitions for ‘x’ + Bound at: Lib.hs:8:9-10 + Lib.hs:8:13 + • In an equation for ‘foo’ + | +8 | foo Foo{..} x = x + y + | +``` + +Consider using `NamedFieldPuns` to be more explicit +about which variables are bound where.