-
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
2574280
commit 18a7b18
Showing
5 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
message-index/messages/GHC-02256/ambiguous/after/AmbiguousA.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,7 @@ | ||
{-# LANGUAGE DuplicateRecordFields #-} | ||
module AmbiguousA where | ||
|
||
data Foo = Foo { foo :: Int } | ||
|
||
data Bar = Bar { foo :: Int } | ||
|
7 changes: 7 additions & 0 deletions
7
message-index/messages/GHC-02256/ambiguous/after/AmbiguousB.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,7 @@ | ||
module AmbiguousB where | ||
|
||
import qualified AmbiguousA as Foo (Foo(..)) | ||
import qualified AmbiguousA as Bar (Bar(..)) | ||
|
||
blah :: Bar.Bar -> Bar.Bar | ||
blah bar = bar { Bar.foo = 5 } |
9 changes: 9 additions & 0 deletions
9
message-index/messages/GHC-02256/ambiguous/before/AmbiguousA.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,9 @@ | ||
{-# LANGUAGE DuplicateRecordFields #-} | ||
module Ambiguous where | ||
|
||
data Foo = Foo { foo :: Int } | ||
|
||
data Bar = Bar { foo :: Int } | ||
|
||
blah :: Bar -> Bar | ||
blah bar = bar { foo = 5 } |
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,17 @@ | ||
--- | ||
title: Ambiguous Record Update | ||
--- | ||
|
||
In this example we declare two records `Foo` and `Bar` which each contain a field with the same name `foo`. In the function `blah` we use this name to update the field in a record of type `Bar`. | ||
The compiler can successfully detect that the field `foo` that we mention in the record update can only refer to the field of the record `Bar`, but the mechanism that GHC uses for this will be deprecated in a future release, and for this reason a warning is emitted. | ||
|
||
``` | ||
before/Ambiguous.hs:9:18: warning: [GHC-02256] [-Wambiguous-fields] | ||
The record update bar {foo = 5} with type Bar is ambiguous. | ||
This will not be supported by -XDuplicateRecordFields in future releases of GHC. | ||
| | ||
9 | blah bar = bar { foo = 5 } | ||
| | ||
``` | ||
|
||
In order to make your code compile without any warnings you can put the declarations of both records in a separate module, and use qualified imports and qualified names to make it unambiguous which record field you mean. |
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,10 @@ | ||
--- | ||
title: Ambiguous record update | ||
summary: Record update with duplicate field names is ambiguous | ||
severity: warning | ||
flag: -Wambiguous-fields | ||
introduced: 9.6.1 | ||
--- | ||
|
||
With the `DuplicateRecordFields` extension enabled it is possible to use the same field name in multiple records within the same module. | ||
This can lead to problems when using field accessors to access a field of a record. |