Ticket #2584 (closed bug: fixed)

Opened 5 years ago

Last modified 4 years ago

Pretty printing of types with HsDocTy goes wrong

Reported by: NeilMitchell Owned by: waern
Priority: high Milestone: 6.10.2
Component: Compiler Version: 6.9
Keywords: Cc: neil.mitchell.2@…, ganesh.sittampalam@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

Pretty printing of type signatures containing HsDocTy? goes wrong in HEAD. This manifests itself as serious bugs in both Haddock and Hoogle. Because the bug causes Haddock generated documentation to be wrong, I've marked the severity as major.

Take the following file:

{-# LANGUAGE FlexibleInstances #-}

import GHC
import SrcLoc
import Outputable

main = do
	putStrLn $ out $ HsFunTy fun fun
	putStrLn $ out $ HsFunTy (doc fun) fun

reL = L undefined
out x = showSDoc $ ppr x
fun = reL $ HsFunTy (reL $ HsTyVar "a") (reL $ HsTyVar "b") 
doc = reL . flip HsDocTy undefined

instance OutputableBndr [Char] where
	pprBndr _ x = text x

The output is:

C:\Neil>runghc "-package ghc" test2.hs
([a] -> [b]) -> [a] -> [b]
[a] -> [b] <document comment> -> [a] -> [b]

Note that the first line (correctly) brackets the type signature, but that the second (incorrectly) omits the brackets. I suggest a change to the pretty printer to ignore HsTyDoc? when determining where to insert brackets - or even removing the pretty printing of HsTyDoc? entirely.

-- Neil

Change History

Changed 5 years ago by NeilMitchell

This bug can be tickled from haddock with the file:

module Test where

unmap :: (a -> b) -- ^comment
      -> a
unmap f = undefined

In the generated documentation all brackets are missing.

Changed 5 years ago by waern

  • owner set to waern
  • status changed from new to assigned

Changed 5 years ago by igloo

  • difficulty set to Unknown
  • milestone set to 6.10.1

Changed 5 years ago by simonmar

  • architecture changed from Unknown to Unknown/Multiple

Changed 5 years ago by simonmar

  • os changed from Unknown to Unknown/Multiple

Changed 5 years ago by igloo

  • priority changed from normal to high

Changed 5 years ago by igloo

  • milestone changed from 6.10.1 to 6.10.2

Changed 4 years ago by NeilMitchell

I have now worked around this bug in Hoogle, in quite a clean way, so this no longer effects development builds of Hoogle. If I had been able to use SYB the workaround would have been 15x shorter and much more robust...

I did track the bug down somewhat in GHC - see compiler\hsSyn\HsTypes?.lhs, line 379:

ppr_mono_ty _         (HsDocTy ty doc)
  = ppr ty <+> ppr (unLoc doc)

All the other ppr_mono_ty functions have a maybeParen call first, which is missing here. You'll need to figure out the relative priorities etc. Or perhaps just remove HsDocTy?'s when pretty printing?

Changed 4 years ago by waern

  • status changed from assigned to closed
  • resolution set to fixed

I don't want remove the pretty printing of HsDocTy since it is used by the test suite, to test that parsing works correctly. So I've fixed the pretty printing so that the comments are handled as if they were postfix type operators. Your example now becomes:

([a] -> [b]) <document comment> -> [a] -> [b]

This is the patch (in HEAD):

Fri Jan  9 20:17:13 CET 2009  David Waern <david.waern@gmail.com>
  * Fix Trac #2584: Pretty printing of types with HsDocTy

Changed 4 years ago by igloo

Merged to 6.10

Note: See TracTickets for help on using tickets.