diff options
-rw-r--r-- | compiler/parser/Parser.y | 13 | ||||
-rw-r--r-- | testsuite/tests/parser/should_compile/T17561.hs | 3 | ||||
-rw-r--r-- | testsuite/tests/parser/should_compile/all.T | 1 |
3 files changed, 15 insertions, 2 deletions
diff --git a/compiler/parser/Parser.y b/compiler/parser/Parser.y index ce4d277f6b..7c520d0bd8 100644 --- a/compiler/parser/Parser.y +++ b/compiler/parser/Parser.y @@ -766,13 +766,22 @@ signature :: { Located (HsModule GhcPs) } ([mj AnnSignature $2, mj AnnWhere $6] ++ fst $7) } module :: { Located (HsModule GhcPs) } - : maybedocheader 'module' modid maybemodwarning maybeexports 'where' body + -- it is important that we include both rules below and not use + -- maybedocheader here since we may have a module which begins with a + -- declaration with docstring (see #17561). + : moduleheader 'module' modid maybemodwarning maybeexports 'where' body {% fileSrcSpan >>= \ loc -> ams (L loc (HsModule (Just $3) $5 (fst $ snd $7) (snd $ snd $7) $4 $1) ) ([mj AnnModule $2, mj AnnWhere $6] ++ fst $7) } - | body2 + | 'module' modid maybemodwarning maybeexports 'where' body + {% fileSrcSpan >>= \ loc -> + ams (L loc (HsModule (Just $2) $4 (fst $ snd $6) + (snd $ snd $6) $3 Nothing) + ) + ([mj AnnModule $1, mj AnnWhere $5] ++ fst $6) } + | body2 {% fileSrcSpan >>= \ loc -> ams (L loc (HsModule Nothing Nothing (fst $ snd $1) (snd $ snd $1) Nothing Nothing)) diff --git a/testsuite/tests/parser/should_compile/T17561.hs b/testsuite/tests/parser/should_compile/T17561.hs new file mode 100644 index 0000000000..caddabfbe4 --- /dev/null +++ b/testsuite/tests/parser/should_compile/T17561.hs @@ -0,0 +1,3 @@ +-- | Test whether @-haddock@ mode parses a module lacking a module header +-- correctly . +hello = 42 diff --git a/testsuite/tests/parser/should_compile/all.T b/testsuite/tests/parser/should_compile/all.T index 85a7c3c172..21b7412e19 100644 --- a/testsuite/tests/parser/should_compile/all.T +++ b/testsuite/tests/parser/should_compile/all.T @@ -164,3 +164,4 @@ test('proposal-229f', multimod_compile_and_run, ['proposal-229f.hs', '']) test('T15730a', normal, compile_and_run, ['']) +test('T17561', normal, compile_and_run, ['-haddock']) |