Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
-
faf14e0c
by Vladislav Zavialov at 2026-02-27T05:48:45-05:00
7 changed files:
- compiler/GHC/Hs/Lit.hs
- compiler/GHC/Hs/Type.hs
- + testsuite/tests/parser/should_fail/T26860ppr_overloaded.hs
- + testsuite/tests/parser/should_fail/T26860ppr_overloaded.stderr
- + testsuite/tests/parser/should_fail/T26860ppr_tylit.hs
- + testsuite/tests/parser/should_fail/T26860ppr_tylit.stderr
- testsuite/tests/parser/should_fail/all.T
Changes:
| ... | ... | @@ -21,7 +21,7 @@ import GHC.Prelude |
| 21 | 21 | |
| 22 | 22 | import {-# SOURCE #-} GHC.Hs.Expr( pprExpr )
|
| 23 | 23 | |
| 24 | -import GHC.Data.FastString (unpackFS)
|
|
| 24 | +import GHC.Data.FastString (FastString, unpackFS)
|
|
| 25 | 25 | import GHC.Types.Basic (PprPrec(..), topPrec )
|
| 26 | 26 | import GHC.Core.Ppr ( {- instance OutputableBndr TyVar -} )
|
| 27 | 27 | import GHC.Types.SourceText
|
| ... | ... | @@ -209,10 +209,7 @@ Equivalently it's True if |
| 209 | 209 | instance IsPass p => Outputable (HsLit (GhcPass p)) where
|
| 210 | 210 | ppr (HsChar st c) = pprWithSourceText st (pprHsChar c)
|
| 211 | 211 | ppr (HsCharPrim st c) = pprWithSourceText st (pprPrimChar c)
|
| 212 | - ppr (HsString st s) =
|
|
| 213 | - case st of
|
|
| 214 | - NoSourceText -> pprHsString s
|
|
| 215 | - SourceText src -> vcat $ map text $ split '\n' (unpackFS src)
|
|
| 212 | + ppr (HsString st s) = pprHsStringLit st s
|
|
| 216 | 213 | ppr (HsStringPrim st s) = pprWithSourceText st (pprHsBytes s)
|
| 217 | 214 | ppr (HsInt _ i)
|
| 218 | 215 | = pprWithSourceText (il_text i) (integer (il_value i))
|
| ... | ... | @@ -233,6 +230,10 @@ instance IsPass p => Outputable (HsLit (GhcPass p)) where |
| 233 | 230 | (HsInteger st i _) -> pprWithSourceText st (integer i)
|
| 234 | 231 | (HsRat f _) -> ppr f
|
| 235 | 232 | |
| 233 | +pprHsStringLit :: SourceText -> FastString -> SDoc
|
|
| 234 | +pprHsStringLit NoSourceText s = pprHsString s
|
|
| 235 | +pprHsStringLit (SourceText src) _ = vcat $ map text $ split '\n' (unpackFS src)
|
|
| 236 | + |
|
| 236 | 237 | -- in debug mode, print the expression that it's resolved to, too
|
| 237 | 238 | instance OutputableBndrId p
|
| 238 | 239 | => Outputable (HsOverLit (GhcPass p)) where
|
| ... | ... | @@ -242,7 +243,7 @@ instance OutputableBndrId p |
| 242 | 243 | instance Outputable OverLitVal where
|
| 243 | 244 | ppr (HsIntegral i) = pprWithSourceText (il_text i) (integer (il_value i))
|
| 244 | 245 | ppr (HsFractional f) = ppr f
|
| 245 | - ppr (HsIsString st s) = pprWithSourceText st (pprHsString s)
|
|
| 246 | + ppr (HsIsString st s) = pprHsStringLit st s
|
|
| 246 | 247 | |
| 247 | 248 | negateOverLitVal :: OverLitVal -> OverLitVal
|
| 248 | 249 | negateOverLitVal (HsIntegral i) = HsIntegral (negateIntegralLit i)
|
| ... | ... | @@ -116,6 +116,7 @@ import GHC.Core.Ppr ( pprOccWithTick) |
| 116 | 116 | import GHC.Core.Type
|
| 117 | 117 | import GHC.Core.Multiplicity( pprArrowWithMultiplicity )
|
| 118 | 118 | import GHC.Hs.Doc
|
| 119 | +import GHC.Hs.Lit (pprHsStringLit)
|
|
| 119 | 120 | import GHC.Generics (Generic, Generically(..))
|
| 120 | 121 | import GHC.Types.Basic
|
| 121 | 122 | import GHC.Types.SrcLoc
|
| ... | ... | @@ -1346,7 +1347,7 @@ instance (OutputableBndrId pass) => OutputableBndr (GenLocated SrcSpan (FieldOcc |
| 1346 | 1347 | |
| 1347 | 1348 | ppr_tylit :: (HsTyLit (GhcPass p)) -> SDoc
|
| 1348 | 1349 | ppr_tylit (HsNumTy source i) = pprWithSourceText source (integer i)
|
| 1349 | -ppr_tylit (HsStrTy source s) = pprWithSourceText source (text (show s))
|
|
| 1350 | +ppr_tylit (HsStrTy source s) = pprHsStringLit source s
|
|
| 1350 | 1351 | ppr_tylit (HsCharTy source c) = pprWithSourceText source (text (show c))
|
| 1351 | 1352 | |
| 1352 | 1353 | pprAnonWildCard :: SDoc
|
| 1 | +{-# LANGUAGE OverloadedStrings #-}
|
|
| 2 | + |
|
| 3 | +module T26860ppr_overloaded 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_overloaded.hs:8:5: error: [GHC-39999]
|
|
| 2 | + • No instance for ‘GHC.Internal.Data.String.IsString Int’
|
|
| 3 | + arising from the literal ‘"first line \
|
|
| 4 | + \asdf\n\
|
|
| 5 | + \second line"’
|
|
| 6 | + • In the expression:
|
|
| 7 | + "first line \
|
|
| 8 | + \asdf\n\
|
|
| 9 | + \second line"
|
|
| 10 | + In an equation for ‘x’:
|
|
| 11 | + x = "first line \
|
|
| 12 | + \asdf\n\
|
|
| 13 | + \second line"
|
|
| 14 | + |
| 1 | +{-# LANGUAGE DataKinds #-}
|
|
| 2 | + |
|
| 3 | +module T26860ppr_tylit where
|
|
| 4 | + |
|
| 5 | +import Data.Kind (Type)
|
|
| 6 | + |
|
| 7 | +-- Test that the error message containing the string literal is well-formatted.
|
|
| 8 | +-- See also: parser/should_fail/MultilineStringsError
|
|
| 9 | +type X :: Type
|
|
| 10 | +type X = "first line \
|
|
| 11 | + \asdf\n\
|
|
| 12 | + \second line"
|
|
| 13 | + |
| 1 | +T26860ppr_tylit.hs:10:10: error: [GHC-83865]
|
|
| 2 | + • Expected a type,
|
|
| 3 | + but ‘"first line \
|
|
| 4 | + \asdf\n\
|
|
| 5 | + \second line"’ has kind
|
|
| 6 | + ‘GHC.Internal.Types.Symbol’
|
|
| 7 | + • In the type ‘"first line \
|
|
| 8 | + \asdf\n\
|
|
| 9 | + \second line"’
|
|
| 10 | + In the type synonym declaration for ‘X’
|
|
| 11 | + |
| ... | ... | @@ -245,3 +245,5 @@ test('T26418', normal, compile_fail, ['']) |
| 245 | 245 | test('T12488c', normal, compile_fail, [''])
|
| 246 | 246 | test('T12488d', normal, compile_fail, [''])
|
| 247 | 247 | test('T26860ppr', normal, compile_fail, [''])
|
| 248 | +test('T26860ppr_overloaded', normal, compile_fail, [''])
|
|
| 249 | +test('T26860ppr_tylit', normal, compile_fail, ['']) |