Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
-
ddf1434f
by Vladislav Zavialov at 2026-02-01T19:38:52-05:00
14 changed files:
- compiler/GHC/Hs/Lit.hs
- compiler/GHC/Hs/Syn/Type.hs
- compiler/GHC/HsToCore/Match/Literal.hs
- compiler/GHC/HsToCore/Quote.hs
- compiler/GHC/Parser.y
- compiler/GHC/Parser/String.hs
- compiler/GHC/Rename/Expr.hs
- compiler/GHC/Tc/Gen/HsType.hs
- compiler/Language/Haskell/Syntax/Extension.hs
- compiler/Language/Haskell/Syntax/Lit.hs
- + testsuite/tests/parser/should_fail/T26860ppr.hs
- + testsuite/tests/parser/should_fail/T26860ppr.stderr
- testsuite/tests/parser/should_fail/all.T
- utils/check-exact/ExactPrint.hs
Changes:
| ... | ... | @@ -45,7 +45,6 @@ import Language.Haskell.Syntax.Lit |
| 45 | 45 | type instance XHsChar (GhcPass _) = SourceText
|
| 46 | 46 | type instance XHsCharPrim (GhcPass _) = SourceText
|
| 47 | 47 | type instance XHsString (GhcPass _) = SourceText
|
| 48 | -type instance XHsMultilineString (GhcPass _) = SourceText
|
|
| 49 | 48 | type instance XHsStringPrim (GhcPass _) = SourceText
|
| 50 | 49 | type instance XHsInt (GhcPass _) = NoExtField
|
| 51 | 50 | type instance XHsIntPrim (GhcPass _) = SourceText
|
| ... | ... | @@ -147,7 +146,6 @@ hsLitNeedsParens p = go |
| 147 | 146 | go (HsChar {}) = False
|
| 148 | 147 | go (HsCharPrim {}) = False
|
| 149 | 148 | go (HsString {}) = False
|
| 150 | - go (HsMultilineString {}) = False
|
|
| 151 | 149 | go (HsStringPrim {}) = False
|
| 152 | 150 | go (HsInt _ x) = p > topPrec && il_neg x
|
| 153 | 151 | go (HsFloatPrim {}) = False
|
| ... | ... | @@ -177,7 +175,6 @@ convertLit :: XXLit (GhcPass p)~DataConCantHappen => HsLit (GhcPass p) -> HsLit |
| 177 | 175 | convertLit (HsChar a x) = HsChar a x
|
| 178 | 176 | convertLit (HsCharPrim a x) = HsCharPrim a x
|
| 179 | 177 | convertLit (HsString a x) = HsString a x
|
| 180 | -convertLit (HsMultilineString a x) = HsMultilineString a x
|
|
| 181 | 178 | convertLit (HsStringPrim a x) = HsStringPrim a x
|
| 182 | 179 | convertLit (HsInt a x) = HsInt a x
|
| 183 | 180 | convertLit (HsIntPrim a x) = HsIntPrim a x
|
| ... | ... | @@ -212,8 +209,7 @@ Equivalently it's True if |
| 212 | 209 | instance IsPass p => Outputable (HsLit (GhcPass p)) where
|
| 213 | 210 | ppr (HsChar st c) = pprWithSourceText st (pprHsChar c)
|
| 214 | 211 | ppr (HsCharPrim st c) = pprWithSourceText st (pprPrimChar c)
|
| 215 | - ppr (HsString st s) = pprWithSourceText st (pprHsString s)
|
|
| 216 | - ppr (HsMultilineString st s) =
|
|
| 212 | + ppr (HsString st s) =
|
|
| 217 | 213 | case st of
|
| 218 | 214 | NoSourceText -> pprHsString s
|
| 219 | 215 | SourceText src -> vcat $ map text $ split '\n' (unpackFS src)
|
| ... | ... | @@ -248,36 +244,6 @@ instance Outputable OverLitVal where |
| 248 | 244 | ppr (HsFractional f) = ppr f
|
| 249 | 245 | ppr (HsIsString st s) = pprWithSourceText st (pprHsString s)
|
| 250 | 246 | |
| 251 | --- | pmPprHsLit pretty prints literals and is used when pretty printing pattern
|
|
| 252 | --- match warnings. All are printed the same (i.e., without hashes if they are
|
|
| 253 | --- primitive and not wrapped in constructors if they are boxed). This happens
|
|
| 254 | --- mainly for too reasons:
|
|
| 255 | --- * We do not want to expose their internal representation
|
|
| 256 | --- * The warnings become too messy
|
|
| 257 | -pmPprHsLit :: forall p. IsPass p => HsLit (GhcPass p) -> SDoc
|
|
| 258 | -pmPprHsLit (HsChar _ c) = pprHsChar c
|
|
| 259 | -pmPprHsLit (HsCharPrim _ c) = pprHsChar c
|
|
| 260 | -pmPprHsLit (HsString st s) = pprWithSourceText st (pprHsString s)
|
|
| 261 | -pmPprHsLit (HsMultilineString st s) = pprWithSourceText st (pprHsString s)
|
|
| 262 | -pmPprHsLit (HsStringPrim _ s) = pprHsBytes s
|
|
| 263 | -pmPprHsLit (HsInt _ i) = integer (il_value i)
|
|
| 264 | -pmPprHsLit (HsIntPrim _ i) = integer i
|
|
| 265 | -pmPprHsLit (HsWordPrim _ w) = integer w
|
|
| 266 | -pmPprHsLit (HsInt8Prim _ i) = integer i
|
|
| 267 | -pmPprHsLit (HsInt16Prim _ i) = integer i
|
|
| 268 | -pmPprHsLit (HsInt32Prim _ i) = integer i
|
|
| 269 | -pmPprHsLit (HsInt64Prim _ i) = integer i
|
|
| 270 | -pmPprHsLit (HsWord8Prim _ w) = integer w
|
|
| 271 | -pmPprHsLit (HsWord16Prim _ w) = integer w
|
|
| 272 | -pmPprHsLit (HsWord32Prim _ w) = integer w
|
|
| 273 | -pmPprHsLit (HsWord64Prim _ w) = integer w
|
|
| 274 | -pmPprHsLit (HsFloatPrim _ f) = ppr f
|
|
| 275 | -pmPprHsLit (HsDoublePrim _ d) = ppr d
|
|
| 276 | -pmPprHsLit (XLit x) = case ghcPass @p of
|
|
| 277 | - GhcTc -> case x of
|
|
| 278 | - (HsInteger _ i _) -> integer i
|
|
| 279 | - (HsRat f _) -> ppr f
|
|
| 280 | - |
|
| 281 | 247 | negateOverLitVal :: OverLitVal -> OverLitVal
|
| 282 | 248 | negateOverLitVal (HsIntegral i) = HsIntegral (negateIntegralLit i)
|
| 283 | 249 | negateOverLitVal (HsFractional f) = HsFractional (negateFractionalLit f)
|
| ... | ... | @@ -75,7 +75,6 @@ hsLitType :: forall p. IsPass p => HsLit (GhcPass p) -> Type |
| 75 | 75 | hsLitType (HsChar _ _) = charTy
|
| 76 | 76 | hsLitType (HsCharPrim _ _) = charPrimTy
|
| 77 | 77 | hsLitType (HsString _ _) = stringTy
|
| 78 | -hsLitType (HsMultilineString _ _) = stringTy
|
|
| 79 | 78 | hsLitType (HsStringPrim _ _) = addrPrimTy
|
| 80 | 79 | hsLitType (HsInt _ _) = intTy
|
| 81 | 80 | hsLitType (HsIntPrim _ _) = intPrimTy
|
| ... | ... | @@ -117,7 +117,6 @@ dsLit l = do |
| 117 | 117 | HsDoublePrim _ fl -> return (Lit (LitDouble (rationalFromFractionalLit fl)))
|
| 118 | 118 | HsChar _ c -> return (mkCharExpr c)
|
| 119 | 119 | HsString _ str -> mkStringExprFS str
|
| 120 | - HsMultilineString _ str -> mkStringExprFS str
|
|
| 121 | 120 | HsInt _ i -> return (mkIntExpr platform (il_value i))
|
| 122 | 121 | XLit x -> case ghcPass @p of
|
| 123 | 122 | GhcTc -> case x of
|
| ... | ... | @@ -463,7 +462,6 @@ getSimpleIntegralLit (XLit (HsInteger _ i ty)) = Just (i, ty) |
| 463 | 462 | getSimpleIntegralLit HsChar{} = Nothing
|
| 464 | 463 | getSimpleIntegralLit HsCharPrim{} = Nothing
|
| 465 | 464 | getSimpleIntegralLit HsString{} = Nothing
|
| 466 | -getSimpleIntegralLit HsMultilineString{} = Nothing
|
|
| 467 | 465 | getSimpleIntegralLit HsStringPrim{} = Nothing
|
| 468 | 466 | getSimpleIntegralLit (XLit (HsRat{})) = Nothing
|
| 469 | 467 | getSimpleIntegralLit HsFloatPrim{} = Nothing
|
| ... | ... | @@ -3077,7 +3077,6 @@ repLiteral lit |
| 3077 | 3077 | HsChar _ _ -> Just charLName
|
| 3078 | 3078 | HsCharPrim _ _ -> Just charPrimLName
|
| 3079 | 3079 | HsString _ _ -> Just stringLName
|
| 3080 | - HsMultilineString _ _ -> Just stringLName
|
|
| 3081 | 3080 | _ -> Nothing
|
| 3082 | 3081 | |
| 3083 | 3082 | mk_integer :: Integer -> MetaM (HsLit GhcTc)
|
| ... | ... | @@ -4131,7 +4131,7 @@ literal :: { Located (HsLit GhcPs) } |
| 4131 | 4131 | : CHAR { sL1 $1 $ HsChar (getCHARs $1) $ getCHAR $1 }
|
| 4132 | 4132 | | STRING { sL1 $1 $ HsString (getSTRINGs $1)
|
| 4133 | 4133 | $ getSTRING $1 }
|
| 4134 | - | STRING_MULTI { sL1 $1 $ HsMultilineString (getSTRINGMULTIs $1)
|
|
| 4134 | + | STRING_MULTI { sL1 $1 $ HsString (getSTRINGMULTIs $1)
|
|
| 4135 | 4135 | $ getSTRINGMULTI $1 }
|
| 4136 | 4136 | | PRIMINTEGER { sL1 $1 $ HsIntPrim (getPRIMINTEGERs $1)
|
| 4137 | 4137 | $ getPRIMINTEGER $1 }
|
| ... | ... | @@ -392,9 +392,9 @@ proposal: https://github.com/ghc-proposals/ghc-proposals/pull/569 |
| 392 | 392 | |
| 393 | 393 | Multiline string literals are syntax sugar for normal string literals,
|
| 394 | 394 | with an extra post processing step. This all happens in the Lexer; that
|
| 395 | -is, HsMultilineString will contain the post-processed string. This matches
|
|
| 396 | -the same behavior as HsString, which contains the normalized string
|
|
| 397 | -(see Note [Literal source text]).
|
|
| 395 | +is, the multi-line HsString will contain the post-processed string.
|
|
| 396 | +This matches the behavior of the single-line HsString, which contains
|
|
| 397 | +the normalized string too (see Note [Literal source text]).
|
|
| 398 | 398 | |
| 399 | 399 | The canonical steps for post processing a multiline string are:
|
| 400 | 400 | 1. Collapse string gaps
|
| ... | ... | @@ -352,18 +352,13 @@ rnExpr (HsOverLabel src v) |
| 352 | 352 | hs_ty_arg = mkEmptyWildCardBndrs $ wrapGenSpan $
|
| 353 | 353 | HsTyLit noExtField (HsStrTy NoSourceText v)
|
| 354 | 354 | |
| 355 | -rnExpr (HsLit x lit) | Just (src, s) <- stringLike lit
|
|
| 355 | +rnExpr (HsLit x lit) | HsString src s <- lit
|
|
| 356 | 356 | = do { opt_OverloadedStrings <- xoptM LangExt.OverloadedStrings
|
| 357 | 357 | ; if opt_OverloadedStrings then
|
| 358 | 358 | rnExpr (HsOverLit x (mkHsIsString src s))
|
| 359 | 359 | else do {
|
| 360 | 360 | ; rnLit lit
|
| 361 | 361 | ; return (HsLit x (convertLit lit), emptyFVs) } }
|
| 362 | - where
|
|
| 363 | - stringLike = \case
|
|
| 364 | - HsString src s -> Just (src, s)
|
|
| 365 | - HsMultilineString src s -> Just (src, s)
|
|
| 366 | - _ -> Nothing
|
|
| 367 | 362 | |
| 368 | 363 | rnExpr (HsLit x lit)
|
| 369 | 364 | = do { rnLit lit
|
| ... | ... | @@ -4786,7 +4786,6 @@ promotionErr name err |
| 4786 | 4786 | |
| 4787 | 4787 | tyLitFromLit :: HsLit GhcRn -> Maybe (HsTyLit GhcRn)
|
| 4788 | 4788 | tyLitFromLit (HsString x str) = Just (HsStrTy x str)
|
| 4789 | -tyLitFromLit (HsMultilineString x str) = Just (HsStrTy x str)
|
|
| 4790 | 4789 | tyLitFromLit (HsChar x char) = Just (HsCharTy x char)
|
| 4791 | 4790 | tyLitFromLit _ = Nothing
|
| 4792 | 4791 |
| ... | ... | @@ -609,7 +609,6 @@ type family XXParStmtBlock x x' |
| 609 | 609 | type family XHsChar x
|
| 610 | 610 | type family XHsCharPrim x
|
| 611 | 611 | type family XHsString x
|
| 612 | -type family XHsMultilineString x
|
|
| 613 | 612 | type family XHsStringPrim x
|
| 614 | 613 | type family XHsInt x
|
| 615 | 614 | type family XHsIntPrim x
|
| ... | ... | @@ -47,8 +47,6 @@ data HsLit x |
| 47 | 47 | -- ^ Unboxed character
|
| 48 | 48 | | HsString (XHsString x) {- SourceText -} FastString
|
| 49 | 49 | -- ^ String
|
| 50 | - | HsMultilineString (XHsMultilineString x) {- SourceText -} FastString
|
|
| 51 | - -- ^ String
|
|
| 52 | 50 | | HsStringPrim (XHsStringPrim x) {- SourceText -} !ByteString
|
| 53 | 51 | -- ^ Packed bytes
|
| 54 | 52 | | HsInt (XHsInt x) IntegralLit
|
| 1 | +{-# LANGUAGE NoOverloadedStrings #-}
|
|
| 2 | + |
|
| 3 | +module T26860ppr where
|
|
| 4 | + |
|
| 5 | +-- Test that the error message containing the string literal is well-formatted.
|
|
| 6 | +-- See also: parser/should_fail/MultilineStringsError
|
|
| 7 | +x :: Int
|
|
| 8 | +x = "first line \
|
|
| 9 | + \asdf\n\
|
|
| 10 | + \second line"
|
|
| 11 | + |
| 1 | +T26860ppr.hs:8:5: error: [GHC-83865]
|
|
| 2 | + • Couldn't match type ‘[Char]’ with ‘Int’
|
|
| 3 | + Expected: Int
|
|
| 4 | + Actual: String
|
|
| 5 | + • In the expression:
|
|
| 6 | + "first line \
|
|
| 7 | + \asdf\n\
|
|
| 8 | + \second line"
|
|
| 9 | + In an equation for ‘x’:
|
|
| 10 | + x = "first line \
|
|
| 11 | + \asdf\n\
|
|
| 12 | + \second line"
|
|
| 13 | + |
| ... | ... | @@ -244,3 +244,4 @@ test('T25530', normal, compile_fail, ['']) |
| 244 | 244 | test('T26418', normal, compile_fail, [''])
|
| 245 | 245 | test('T12488c', normal, compile_fail, [''])
|
| 246 | 246 | test('T12488d', normal, compile_fail, [''])
|
| 247 | +test('T26860ppr', normal, compile_fail, ['']) |
| ... | ... | @@ -4794,7 +4794,6 @@ hsLit2String lit = |
| 4794 | 4794 | HsChar src v -> toSourceTextWithSuffix src v ""
|
| 4795 | 4795 | HsCharPrim src p -> toSourceTextWithSuffix src p ""
|
| 4796 | 4796 | HsString src v -> toSourceTextWithSuffix src v ""
|
| 4797 | - HsMultilineString src v -> toSourceTextWithSuffix src v ""
|
|
| 4798 | 4797 | HsStringPrim src v -> toSourceTextWithSuffix src v ""
|
| 4799 | 4798 | HsInt _ (IL src _ v) -> toSourceTextWithSuffix src v ""
|
| 4800 | 4799 | HsIntPrim src v -> toSourceTextWithSuffix src v ""
|