Skip to content

LANGUAGE CPP messes up parsing when backslash like \\ is at end of line (eol)

{-# LANGUAGE CPP #-}

import Data.List as List

main = putStrLn $
  "not nice" List.\\
    "hot mice"

fails with recent ghc (I tried >= 7.8).

    Not in scope: ‘List.\’

This problem occurred in a larger context, see https://travis-ci.org/agda/agda/jobs/144514733

It can be traced back to the use of cpp as preprocessor:

$ cpp BackslashAtEOL.hs
# 1 "BackslashAtEOL.hs"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 328 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "BackslashAtEOL.hs" 2
{-# LANGUAGE CPP #-}

import Data.List as List

main = putStrLn $
  "not nice" List.\     "hot mice"

In contrast, cpphs would work correctly here:

$ cpphs BackslashAtEOL.hs
#line 1 "BackslashAtEOL.hs"
{-# LANGUAGE CPP #-}

import Data.List as List

main = putStrLn $
  "not nice" List.\\
    "hot mice"
Trac metadata
Trac field Value
Version 8.0.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Parser)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information