summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladislav Zavialov <vlad.z.4096@gmail.com>2021-03-12 18:11:02 +0300
committerVladislav Zavialov <vlad.z.4096@gmail.com>2021-03-14 13:25:17 -0400
commite5f7ffa4436a6e317d5372c00263e391faba1952 (patch)
treee1f83849dc9cc82b52238754d46fcba54f4189b7
parentce345c44a2608a6b1a4ae723a27dbae7fcfa86f3 (diff)
downloadhaskell-wip/record-dot-precedence.tar.gz
Test chained record construction/update/accesswip/record-dot-precedence
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, [''])