From 4cfeca02a0a9283e8c9f9ccd9373bc1f2fd8db0a Mon Sep 17 00:00:00 2001 From: Alan Zimmerman <alan.zimm@gmail.com> Date: Tue, 26 Jun 2018 11:07:07 +0200 Subject: [PATCH] API Annotations when parsing typapp Make sure the original annotations are still accessible for a promoted type. Closes #15303 (cherry picked from commit e53c113dcfeca9ee957722ede3d8b6a2c4c751a1) --- compiler/parser/Parser.y | 4 +-- testsuite/tests/ghc-api/annotations/Makefile | 4 +++ .../tests/ghc-api/annotations/T15303.stdout | 35 +++++++++++++++++++ .../tests/ghc-api/annotations/Test15303.hs | 6 ++++ testsuite/tests/ghc-api/annotations/all.T | 2 ++ 5 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 testsuite/tests/ghc-api/annotations/T15303.stdout create mode 100644 testsuite/tests/ghc-api/annotations/Test15303.hs diff --git a/compiler/parser/Parser.y b/compiler/parser/Parser.y index 6b0317bd9c9b..d038562a733e 100644 --- a/compiler/parser/Parser.y +++ b/compiler/parser/Parser.y @@ -1930,9 +1930,9 @@ tyapp :: { Located TyEl } | qtyconop { sL1 $1 $ TyElOpr (unLoc $1) } | tyvarop { sL1 $1 $ TyElOpr (unLoc $1) } | SIMPLEQUOTE qconop {% ams (sLL $1 $> $ TyElOpr (unLoc $2)) - [mj AnnSimpleQuote $1] } + [mj AnnSimpleQuote $1,mj AnnVal $2] } | SIMPLEQUOTE varop {% ams (sLL $1 $> $ TyElOpr (unLoc $2)) - [mj AnnSimpleQuote $1] } + [mj AnnSimpleQuote $1,mj AnnVal $2] } atype_docs :: { LHsType GhcPs } : atype docprev { sLL $1 $> $ HsDocTy noExt $1 $2 } diff --git a/testsuite/tests/ghc-api/annotations/Makefile b/testsuite/tests/ghc-api/annotations/Makefile index 2da5fc00a968..98b45744ce77 100644 --- a/testsuite/tests/ghc-api/annotations/Makefile +++ b/testsuite/tests/ghc-api/annotations/Makefile @@ -141,3 +141,7 @@ T12417: .PHONY: T13163 T13163: $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test13163.hs + +.PHONY: T15303 +T15303: + $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test15303.hs diff --git a/testsuite/tests/ghc-api/annotations/T15303.stdout b/testsuite/tests/ghc-api/annotations/T15303.stdout new file mode 100644 index 000000000000..003dab576121 --- /dev/null +++ b/testsuite/tests/ghc-api/annotations/T15303.stdout @@ -0,0 +1,35 @@ +---Problems (should be empty list)--- +[] +---Annotations----------------------- +-- SrcSpan the annotation is attached to, AnnKeywordId, +-- list of locations the keyword item appears in +[ +((Test15303.hs:4:1-4,AnnCloseP), [Test15303.hs:4:4]), +((Test15303.hs:4:1-4,AnnOpenP), [Test15303.hs:4:1]), +((Test15303.hs:4:1-4,AnnVal), [Test15303.hs:4:2-3]), +((Test15303.hs:4:1-66,AnnDcolon), [Test15303.hs:4:6-7]), +((Test15303.hs:4:1-66,AnnSemi), [Test15303.hs:5:1]), +((Test15303.hs:4:9-17,AnnDarrow), [Test15303.hs:4:19-20]), +((Test15303.hs:4:22-41,AnnRarrow), [Test15303.hs:4:43-44]), +((Test15303.hs:4:22-66,AnnRarrow), [Test15303.hs:4:43-44]), +((Test15303.hs:4:33-41,AnnCloseP), [Test15303.hs:4:41]), +((Test15303.hs:4:33-41,AnnOpenP), [Test15303.hs:4:33]), +((Test15303.hs:4:36-37,AnnSimpleQuote), [Test15303.hs:4:36]), +((Test15303.hs:4:36-37,AnnVal), [Test15303.hs:4:37]), +((Test15303.hs:4:46-48,AnnRarrow), [Test15303.hs:4:50-51]), +((Test15303.hs:4:46-66,AnnRarrow), [Test15303.hs:4:50-51]), +((Test15303.hs:4:58-66,AnnCloseP), [Test15303.hs:4:66]), +((Test15303.hs:4:58-66,AnnOpenP), [Test15303.hs:4:58]), +((Test15303.hs:4:61-62,AnnSimpleQuote), [Test15303.hs:4:61]), +((Test15303.hs:4:61-62,AnnVal), [Test15303.hs:4:62]), +((Test15303.hs:5:1-4,AnnCloseP), [Test15303.hs:5:4]), +((Test15303.hs:5:1-4,AnnOpenP), [Test15303.hs:5:1]), +((Test15303.hs:5:1-4,AnnVal), [Test15303.hs:5:2-3]), +((Test15303.hs:5:1-15,AnnEqual), [Test15303.hs:5:6]), +((Test15303.hs:5:1-15,AnnFunId), [Test15303.hs:5:1-4]), +((Test15303.hs:5:1-15,AnnSemi), [Test15303.hs:6:1]), +((Test15303.hs:6:1-11,AnnInfix), [Test15303.hs:6:1-6]), +((Test15303.hs:6:1-11,AnnSemi), [Test15303.hs:7:1]), +((Test15303.hs:6:1-11,AnnVal), [Test15303.hs:6:8]), +((<no location info>,AnnEofPos), [Test15303.hs:7:1]) +] diff --git a/testsuite/tests/ghc-api/annotations/Test15303.hs b/testsuite/tests/ghc-api/annotations/Test15303.hs new file mode 100644 index 000000000000..212e9da5accb --- /dev/null +++ b/testsuite/tests/ghc-api/annotations/Test15303.hs @@ -0,0 +1,6 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE TypeOperators #-} + +(~#) :: Comonad w => CascadeW w (t ': ts) -> w t -> Last (t ': ts) +(~#) = cascadeW +infixr 0 ~# diff --git a/testsuite/tests/ghc-api/annotations/all.T b/testsuite/tests/ghc-api/annotations/all.T index adc0d14370e8..666cb3f044a5 100644 --- a/testsuite/tests/ghc-api/annotations/all.T +++ b/testsuite/tests/ghc-api/annotations/all.T @@ -57,3 +57,5 @@ test('T12417', [extra_files(['Test12417.hs']), ignore_stderr], run_command, ['$MAKE -s --no-print-directory T12417']) test('T13163', [extra_files(['Test13163.hs']), ignore_stderr], run_command, ['$MAKE -s --no-print-directory T13163']) +test('T15303', [extra_files(['Test15303.hs']), + ignore_stderr], run_command, ['$MAKE -s --no-print-directory T15303']) -- GitLab