summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladislav Zavialov <vlad.z.4096@gmail.com>2021-03-12 18:11:02 +0300
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-03-15 00:43:05 -0400
commit545cfefaa88b31daa2cb3519b7561171e7ca51b3 (patch)
treea72c9203b645f29fd75460df59e7d6a4f9744eae
parent92d98424bf7f8bbd55e1b123d0755c9d52f123dd (diff)
downloadhaskell-545cfefaa88b31daa2cb3519b7561171e7ca51b3.tar.gz
Test chained record construction/update/access
According to the proposal, we have the following equivalence: e{lbl1 = val1}.val2 == (e{lbl1 = val1}).val2 This is a matter of parsing. Record construction/update must have the same precedence as dot access. Add a test case to ensure this.
-rw-r--r--testsuite/tests/parser/should_run/RecordDotSyntax5.hs15
-rw-r--r--testsuite/tests/parser/should_run/RecordDotSyntax5.stdout2
-rw-r--r--testsuite/tests/parser/should_run/all.T1
3 files changed, 18 insertions, 0 deletions
diff --git a/testsuite/tests/parser/should_run/RecordDotSyntax5.hs b/testsuite/tests/parser/should_run/RecordDotSyntax5.hs
new file mode 100644
index 0000000000..72749e876f
--- /dev/null
+++ b/testsuite/tests/parser/should_run/RecordDotSyntax5.hs
@@ -0,0 +1,15 @@
+{-# LANGUAGE OverloadedRecordDot #-}
+{-# LANGUAGE DataKinds #-}
+
+import GHC.Records
+
+data Pair t = P { a, b :: t }
+
+instance Num t => HasField "sum" (Pair t) t where
+ getField p = p.a + p.b
+
+newtype Wrap = W { p :: Pair Double }
+
+main = do
+ print $ P{ a = 40, b = 2 }.sum
+ print $ W{ p = P 0 0 }.p{ a = 1 }{ b = 10 }.sum
diff --git a/testsuite/tests/parser/should_run/RecordDotSyntax5.stdout b/testsuite/tests/parser/should_run/RecordDotSyntax5.stdout
new file mode 100644
index 0000000000..5d68dd9d70
--- /dev/null
+++ b/testsuite/tests/parser/should_run/RecordDotSyntax5.stdout
@@ -0,0 +1,2 @@
+42
+11.0
diff --git a/testsuite/tests/parser/should_run/all.T b/testsuite/tests/parser/should_run/all.T
index caf0e2bc65..5c2112057e 100644
--- a/testsuite/tests/parser/should_run/all.T
+++ b/testsuite/tests/parser/should_run/all.T
@@ -27,3 +27,4 @@ test('RecordDotSyntax1', normal, compile_and_run, [''])
test('RecordDotSyntax2', normal, compile_and_run, [''])
test('RecordDotSyntax3', [extra_files(['RecordDotSyntaxA.hs'])], multimod_compile_and_run, ['RecordDotSyntax3', ''])
test('RecordDotSyntax4', [extra_files(['RecordDotSyntaxA.hs'])], multimod_compile_and_run, ['RecordDotSyntax4', ''])
+test('RecordDotSyntax5', normal, compile_and_run, [''])