Skip to content

CPP produces diagnostics with column number 0

Summary

CPP errors and warning can produce diagnostics with column number 0. This seems surprising given that the column numbers in GHC are usually 1-based. Not sure if this is intended.

Discovered by a user of vscode-ghc-simple: https://github.com/dramforever/vscode-ghc-simple/issues/88.

Steps to reproduce

Put this in ifdef-zero.hs:

{-# LANGUAGE CPP #-}
#ifdef a(b)
#endif

And load it:

GHCi, version 9.0.1: https://www.haskell.org/ghc/  :? for help
ghci> :l ifdef-zero.hs 

ifdef-zero.hs:2:0: error:
     warning: extra tokens at end of #ifdef directive
        2 | #ifdef a(b)
          | 
  |
2 | #ifdef a(b)
  | ^
[1 of 1] Compiling Main             ( ifdef-zero.hs, interpreted )
Ok, one module loaded.

Note the location is specified as 2:0.

Expected behavior

Column numbers start at 1 in GHC, so 0 should not be possible and this should be 1 instead.

Environment

  • GHC version used: 9.0.1

Optional:

  • Operating System: NixOS (Linux)
  • System Architecture: x86_64-linux
Edited by dramforever
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information