haskell / alex

A lexical analyser generator for Haskell
https://hackage.haskell.org/package/alex
BSD 3-Clause "New" or "Revised" License
297 stars 82 forks source link

Int/Int64 issue with ByteString wrappers #80

Closed nikomi closed 8 years ago

nikomi commented 8 years ago

Using %wrapper "monad-bytestring" (or monadUserState-bytestring) results in a compiler error:

templates/wrappers.hs:347:9:
    Couldn't match type ‘Int’ with ‘Int64’
    Expected type: AlexInput → Int64 → Alex Token
      Actual type: (AlexPosn, Char, ByteString.ByteString, [Char])
                   → Int → Alex Token
    In a stmt of a 'do' block: action (ignorePendingBytes inp) len
    In the expression:
      do { alexSetInput inp';
           action (ignorePendingBytes inp) len }
    In a case alternative:
        AlexToken inp'@(_, _, _, n') _ action
          -> do { alexSetInput inp';
                  action (ignorePendingBytes inp) len }
          where
              len = n' - n

This seems to be caused by the definitions

data AlexReturn a
  = AlexEOF
  | AlexError  !AlexInput
  | AlexSkip   !AlexInput !Int
  | AlexToken  !AlexInput !Int a

and

alexMonadScan = do
  inp@(_,_,str,n) <- alexGetInput
  sc <- alexGetStartCode
  case alexScan inp sc of
    AlexEOF -> alexEOF
    AlexError ((AlexPn _ line column),_,_,_) -> alexError $ "lexical error at line " ++ (show line) ++ ", column " ++ (show column)
    AlexSkip  inp' len -> do
        alexSetInput inp'
        alexMonadScan
    AlexToken inp'@(_,_,_,n') _ action -> do
        alexSetInput inp'
        action (ignorePendingBytes inp) len
      where
        len = n'-n

together with ByteString using Int64 for lengths.

hvr commented 8 years ago

I can't seem to be able to reproduce this. In fact, the tests from the testsuite,

seem to compile just fine...

nikomi commented 8 years ago

I can't seem to be able to reproduce this problem in a smaller sample - I'll just write it off as a problem restricted to the given project and close this issue.

Sorry for the inconvenience.