From e5f7ffa4436a6e317d5372c00263e391faba1952 Mon Sep 17 00:00:00 2001 From: Vladislav Zavialov Date: Fri, 12 Mar 2021 18:11:02 +0300 Subject: 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. --- testsuite/tests/parser/should_run/RecordDotSyntax5.hs | 15 +++++++++++++++ testsuite/tests/parser/should_run/RecordDotSyntax5.stdout | 2 ++ testsuite/tests/parser/should_run/all.T | 1 + 3 files changed, 18 insertions(+) create mode 100644 testsuite/tests/parser/should_run/RecordDotSyntax5.hs create mode 100644 testsuite/tests/parser/should_run/RecordDotSyntax5.stdout 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, ['']) -- cgit v1.2.1