Opened 5 years ago

Closed 5 years ago

#6145 closed bug (fixed)

DataCon do not have location info

Reported by: JeanPhilippeMoresmau Owned by:
Priority: normal Milestone:
Component: GHC API Version: 7.4.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect result at runtime Test Case: ghc-api/T6145
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description (last modified by simonpj)

A data constructor does not have a valid source location associated with it in the API. The sample code attached will print True in 7.0.4 and False in 7.4.1, because no valid srcspan is attached to the DataCon. This is a problem for several EclipseFP/BuildWrapper operations that rely on srcspan being right... I've notified the mailing list of the issue, and Simon Peyton Jones was kind enough to fix it without an issue, but I wanted to create it, hopefully I'll try the next nightly release:

commit cb705a38d677e2ab4cad37447c8180bd397d5576
Author: Simon Peyton Jones <>
Date:   Tue Jun 5 13:35:07 2012 +0100

   Add sensible locations to record-selector bindings

 compiler/typecheck/TcTyClsDecls.lhs |   26 +++++++++++++-------------
 1 files changed, 13 insertions(+), 13 deletions(-)

Attachments (1)

Main.hs (1.4 KB) - added by JeanPhilippeMoresmau 5 years ago.
File loading sample code and printing True if there is a valid SrcSpan attached to the DataCon, False otherwise

Download all attachments as: .zip

Change History (6)

Changed 5 years ago by JeanPhilippeMoresmau

Attachment: Main.hs added

File loading sample code and printing True if there is a valid SrcSpan attached to the DataCon, False otherwise

comment:1 Changed 5 years ago by simonpj

Description: modified (diff)
difficulty: Unknown

Thanks. But where is module GHC.Paths?

comment:2 Changed 5 years ago by JeanPhilippeMoresmau

Er, package ghc-paths I think. This is used to get libdir to start the API. I'm sorry, I don't know how you want such a test to be packaged. I've followed the code sample in, thinking that was the canonical way to call the GHC API... If there's a test harness you'd like code like this to fit in I'll be happy to oblige...

comment:3 Changed 5 years ago by simonpj

In our regression suite we try to avoid dependencies on packages that aren't in GHC's build tree, and I don't see package ghc-paths in the tree. I wonder whether it has now become filepath (which is in the tree)? Or maybe you don't need to depend on it at all?


comment:4 Changed 5 years ago by JeanPhilippeMoresmau, to have an easy way to find out where GHC is installed, surely inside the test suite you know where the library directory should be... This is just for the first argument to runGhc (as the docs say: The first argument should point to the directory where GHC's library files reside. More precisely, this should be the output of ghc --print-libdir of the version of GHC the module using this API is compiled with. For portability, you should use the ghc-paths package, available at So maybe using Nothing instead of Just libdir works inside the test suite.

comment:5 Changed 5 years ago by simonpj

Resolution: fixed
Status: newclosed
Test Case: ghc-api/T6145

OK, with a bit of fiddling I made the test work.

Note: See TracTickets for help on using tickets.