Opened 21 months ago

Last modified 14 months ago

#9392 new feature request

"\n" is displayed weirdly in error messages

Reported by: Artyom.Kazak Owned by:
Priority: low Milestone:
Component: Compiler Version: 7.8.3
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Other Test Case:
Blocked By: Blocking:
Related Tickets: #9681 Differential Rev(s):
Wiki Page:

Description

Observe:

Prelude> "a\nb" + ()

<interactive>:2:10:
    Couldn't match expected type ‘[Char]’ with actual type ‘()’
    In the second argument of ‘(+)’, namely ‘()’
    In the expression:
      "a\n\
      \b"
      + ()

Moreover, if “\n” is at the end of the string, it simply gets eaten:

Prelude> "a\n" + ()

<interactive>:3:9:
    Couldn't match expected type ‘[Char]’ with actual type ‘()’
    In the second argument of ‘(+)’, namely ‘()’
    In the expression: "a" + ()

It happens in GHC as well as GHCi. Tested on 7.8.3.

Change History (5)

comment:1 Changed 18 months ago by thomie

  • Keywords newcomer added

The problem with a newline at the end of a string was fixed in #9681, slated for GHC 7.10.1. Let's leave this issue open for the formatting issue.

comment:2 Changed 18 months ago by jlengyel

  • Owner set to jlengyel

comment:3 Changed 18 months ago by jlengyel

  • Owner jlengyel deleted

comment:4 follow-up: Changed 15 months ago by rwbarton

The formatting is intentional, see #4436. It would be nice to use the original syntax, though (and set the "original syntax" of a quasiquoter to use the multiline thing).

comment:5 in reply to: ↑ 4 Changed 14 months ago by thomie

  • Keywords newcomer removed
  • Type changed from bug to feature request

@Artyom.Kazak: what exactly do you find weird about the current error message? The printing over multiple lines, or just the extra slashes that are added. Perhaps the following would be an improvement:

In the expression:
      "a\n
      b"
      + ()

Replying to rwbarton:

The formatting is intentional, see #4436. It would be nice to use the original syntax, though (and set the "original syntax" of a quasiquoter to use the multiline thing).

To show the exception from #4436, the following code path is used:

TcSplice.runMeta -> Outputable.ppr -> (instance Outputable HsLit) -> Outputable.pprHsString -> GHC.Show.showMultiLineString

I don't see an easy way to make the change you propose.

Note: See TracTickets for help on using tickets.