Skip to content

Commit

Permalink
Replace undefined with more descriptive error
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonchinn178 authored and andreasabel committed Dec 30, 2024
1 parent fbbf632 commit a71aa7f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion data/AlexTemplate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ data AlexReturn a

-- alexScan :: AlexInput -> StartCode -> AlexReturn a
alexScan input__ IBOX(sc)
= alexScanUser undefined input__ IBOX(sc)
= alexScanUser (error "alex rule requiring context was invoked by alexScan; use alexScanUser instead?") input__ IBOX(sc)

alexScanUser user__ input__ IBOX(sc)
= case alex_scan_tkn user__ input__ ILIT(0) input__ sc AlexNone of
Expand Down
1 change: 1 addition & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ TESTS = \
issue_119.x \
issue_141.x \
issue_197.x \
issue_262.x \
monad_typeclass.x \
monad_typeclass_bytestring.x \
monadUserState_typeclass.x \
Expand Down
26 changes: 26 additions & 0 deletions tests/issue_262.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
-- https://github.com/haskell/alex/pull/262
-- https://gitlab.haskell.org/ghc/ghc/-/issues/25609
--
-- Error happens when using alexScan with a lexer that
-- inspects the context.

import Control.Exception
import Data.List (isInfixOf)
}

%wrapper "basic"

:-
.* / { \state _ _ _ -> state == 'x' } { id }

{
main :: IO ()
main = do
result <- try $ evaluate $ alexScan ('\n', [], "") 0 `seq` ()
case result of
Left (e :: SomeException)
| "use alexScanUser instead" `isInfixOf` show e
-> pure ()
_ -> error $ "Got unexpected result: " ++ show result
}

0 comments on commit a71aa7f

Please sign in to comment.