[Git][ghc/ghc][master] 2 commits: Fix panic in multiline string with unterminated gap (#25530)
Marge Bot (@marge-bot)
gitlab at gitlab.haskell.org
Mon Dec 9 21:27:22 UTC 2024
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
a8ceccf3 by Brandon Chinn at 2024-12-09T16:25:43-05:00
Fix panic in multiline string with unterminated gap (#25530)
- - - - -
9e464ad0 by Brandon Chinn at 2024-12-09T16:25:43-05:00
Add test case for unterminated multiline string
- - - - -
6 changed files:
- compiler/GHC/Parser/Lexer.x
- + testsuite/tests/parser/should_fail/MultilineStringsUnterminated.hs
- + testsuite/tests/parser/should_fail/MultilineStringsUnterminated.stderr
- + testsuite/tests/parser/should_fail/T25530.hs
- + testsuite/tests/parser/should_fail/T25530.stderr
- testsuite/tests/parser/should_fail/all.T
Changes:
=====================================
compiler/GHC/Parser/Lexer.x
=====================================
@@ -2204,14 +2204,15 @@ tok_string_multi startSpan startBuf _len _buf2 = do
case alexScan i0 string_multi_content of
AlexToken i1 len _
| Just i2 <- lexDelim i1 -> pure (i1, i2)
- | -- is the next token a tab character?
- -- need this explicitly because there's a global rule matching $tab
- Just ('\t', _) <- alexGetChar' i1 -> setInput i1 >> lexError LexError
- | isEOF i1 -> checkSmartQuotes >> lexError LexError
- | len == 0 -> panic $ "parsing multiline string got into infinite loop at: " ++ show i0
+ | isEOF i1 -> checkSmartQuotes >> setInput i1 >> lexError LexError
+ -- is the next token a tab character?
+ -- need this explicitly because there's a global rule matching $tab
+ | Just ('\t', _) <- alexGetChar' i1 -> setInput i1 >> lexError LexError
+ -- Can happen if no patterns match, e.g. an unterminated gap
+ | len == 0 -> setInput i1 >> lexError LexError
| otherwise -> goContent i1
AlexSkip i1 _ -> goContent i1
- _ -> lexError LexError
+ _ -> setInput i0 >> lexError LexError
lexDelim =
let go 0 i = Just i
=====================================
testsuite/tests/parser/should_fail/MultilineStringsUnterminated.hs
=====================================
@@ -0,0 +1,9 @@
+{-# LANGUAGE MultilineStrings #-}
+
+x :: String
+x =
+ """
+ test
+
+y :: Int
+y = 0
=====================================
testsuite/tests/parser/should_fail/MultilineStringsUnterminated.stderr
=====================================
@@ -0,0 +1,3 @@
+MultilineStringsUnterminated.hs:10:1: error: [GHC-21231]
+ lexical error at end of input
+
=====================================
testsuite/tests/parser/should_fail/T25530.hs
=====================================
@@ -0,0 +1,9 @@
+{-# LANGUAGE MultilineStrings #-}
+
+foo =
+ """
+ a\
+ b
+ """
+
+main = print foo
=====================================
testsuite/tests/parser/should_fail/T25530.stderr
=====================================
@@ -0,0 +1,2 @@
+T25530.hs:5:4: error: [GHC-21231] lexical error at character '\\'
+
=====================================
testsuite/tests/parser/should_fail/all.T
=====================================
@@ -231,9 +231,13 @@ test('T17879a', normal, compile_fail, [''])
test('T17879b', normal, compile_fail, [''])
test('Or1', normal, compile_fail, [''])
test('OrPatInExprErr', normal, compile_fail, [''])
+
+# Multiline Strings
test('MultilineStringsError', [normalise_whitespace_fun(lambda s: s)], compile_fail, [''])
test('MultilineStringsSmartQuotes', normal, compile_fail, [''])
test('MultilineStringsInnerTab', normal, compile_fail, [''])
+test('MultilineStringsUnterminated', normal, compile_fail, [''])
test('T25258a', normal, compile_fail, [''])
test('T25258b', normal, compile_fail, [''])
test('T25258c', normal, compile_fail, [''])
+test('T25530', normal, compile_fail, [''])
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/b519c06b889139f7e24f1e84d2e30461cc6cf4a5...9e464ad01f5f60f774504fcaf8d0c30bdd291159
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/b519c06b889139f7e24f1e84d2e30461cc6cf4a5...9e464ad01f5f60f774504fcaf8d0c30bdd291159
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20241209/acf0bf09/attachment-0001.html>
More information about the ghc-commits
mailing list