Ticket #207 (new defect)

Opened 2 years ago

Last modified 2 years ago

haddock: internal error: spliceURL UnhelpfulSpan

Reported by: selinger Owned by:
Priority: major Milestone:
Version: 2.9.4 Keywords:
Cc:

Description

With Haddock 2.8, I got this error message occasionally; with Haddock 2.9.4, I get it *all the time*. Minimal example attached.

The problem seems to arise when one has some function without a type signature, and the --source-entity option is used. The old behavior (2.8) was to ignore such a function. The new behavior is to generate the type signature, but then fail with the above error message.

To reproduce:

haddock -h HaddockBug?.hs --source-entity=HaddockBug?.html#line-%L

Obviously, the above error message was not intended for end users; "Missing type signature" or "Can't find this line in your file" would be a better error message. Still better would be not to produce an error at all.

Attachments

HaddockBug.hs (92 bytes) - added by selinger 2 years ago.

Change History

Changed 2 years ago by selinger

Changed 2 years ago by selinger

Correction: I do not know if this bug was present in 2.8, but I am definitely observing it in 2.9.4 and 2.10.0.

Changed 2 years ago by selinger

Here is a further update. Sorry about the piecemeal format of this bug report; I can't seem to figure out how to edit my original description.

* The problem doesn't seem to be caused by the --source-entity option per se, but rather by the use of %L in the --source-entity option. This is of course indispensable for getting source links to point to the correct source file locations.

* The bug is present in both 2.9.4 and 2.10.0 when Haddock tries to generate documentation for a function that lacks a type signature. However, the difference is that 2.9.4 used to ignore such functions in the case of files having no export list, whereas 2.10.0 tries (and fails) to generate documentation anyway.

The reason this comes up, and "just add a type signature" is not a viable option for me, is that I have functions that are automatically generated by Template Haskell, and they necessarily lack a type signature.

Changed 2 years ago by valiron

In case anyone is interested, I wrote a patch to solve this problem for haddock 2.11.0 and ghc 7.4.2: essentially I filter out the problematic items. The net effect is that exported elements without type signature are not shown in the documentation.

diff -r -u haddock-ghc-7.4.2/src/Haddock/Interface/Create.hs haddock/src/Haddock/Interface/Create.hs
--- haddock-ghc-7.4.2/src/Haddock/Interface/Create.hs   2012-08-30 10:12:42.149210546 -0400
+++ haddock/src/Haddock/Interface/Create.hs     2012-08-30 10:13:08.745620048 -0400
@@ -19,6 +19,7 @@
 import Haddock.Utils
 import Haddock.Convert
 import Haddock.Interface.LexParseRn
+import Haddock.Interface.Rename
 
 import qualified Data.Map as M
 import Data.Map (Map)
@@ -41,6 +42,25 @@
 import TcRnTypes
 import FastString (unpackFS)
 
+-- | To filter out the ExportItem's that are UnhelpfulSpan.
+isHelpfulSpan :: ExportItem Name -> ErrMsgM Bool
+isHelpfulSpan l = case l of
+     (ExportDecl (L (UnhelpfulSpan _) _) _ _ _) -> do
+       tell [concat ["Warning: ", 
+                     extractName l, 
+                     " is exported but does not have a type signature. ",
+                     "Skipping it..."]]
+       return False
+     _ -> return True
+  where
+    
+  -- This is reusing renameExportItem and runRnFM from
+  -- Haddock.Interface.Rename.
+  --
+  -- We use an empty environment for simplicity: for the sake
+  -- of the warning, we know in which module this takes place.
+  extractName :: ExportItem Name -> String
+  extractName e = show $ getOccString $ head $ snd $ runRnFM M.empty $ renameExportItem e
 
 -- | Use a 'TypecheckedModule' to produce an 'Interface'.
 -- To do this, we need access to already processed modules in the topological
@@ -91,6 +111,7 @@
   let warningMap = mkWarningMap warnings gre exportedNames
   exportItems <- mkExportItems modMap mdl warningMap gre exportedNames decls maps exports
                    instances instIfaceMap dflags
+                 >>= (liftErrMsg . filterM isHelpfulSpan)
 
   let visibleNames = mkVisibleNames exportItems opts
 
diff -r -u haddock-ghc-7.4.2/src/Haddock/Interface/Rename.hs haddock/src/Haddock/Interface/Rename.hs
--- haddock-ghc-7.4.2/src/Haddock/Interface/Rename.hs   2012-08-30 10:12:42.149210546 -0400
+++ haddock/src/Haddock/Interface/Rename.hs     2012-08-29 17:12:47.812702645 -0400
@@ -9,7 +9,7 @@
 -- Stability   :  experimental
 -- Portability :  portable
 -----------------------------------------------------------------------------
-module Haddock.Interface.Rename (renameInterface) where
+module Haddock.Interface.Rename (renameInterface,renameExportItem,runRnFM) where
 
 
 import Haddock.GhcUtils

Changed 2 years ago by anonymous

  • milestone 2.10.0 deleted

Milestone 2.10.0 deleted

Note: See TracTickets for help on using tickets.