[GHC] #12146: syntax repair suggestion is too eager to suggest TemplateHaskell

#12146: syntax repair suggestion is too eager to suggest TemplateHaskell -------------------------------------+------------------------------------- Reporter: j.waldmann | Owner: Type: feature | Status: new request | Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- On input `ipmort Data.Monoid`, ghc's suggestion is {{{ Parse error: naked expression at top level Perhaps you intended to use TemplateHaskell }}} Apart from the nudity: the suggestion is unreasonable for beginners, and unnecessary for experts. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12146 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12146: syntax repair suggestion is too eager to suggest TemplateHaskell -------------------------------------+------------------------------------- Reporter: j.waldmann | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by thomie): * keywords: => newcomer * failure: None/Unknown => Incorrect warning at compile-time Comment: Good idea. Do you have a suggestion for what the message should become? The current message was added in #4042 (302e2e29f2e1074bfba561e077a484dc4e1d15f6). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12146#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12146: syntax repair suggestion is too eager to suggest TemplateHaskell -------------------------------------+------------------------------------- Reporter: j.waldmann | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by j.waldmann): * GHC could state that an module header, import declaration or top-level declaration was expected. * GHC should not make any suggestion here. Error messages from the compiler should use exact wording from the language specification [https://www.haskell.org/onlinereport/haskell2010/haskellch5.html#x11-990005....]. I guess "naked" is not in there. For reference: {{{ ipmort java.util.*; class Foo { } Foo.java:1: error: class, interface, or enum expected suing System.Linq; class Foo { } Foo.cs(1,0): error CS1525: Unexpected symbol `suing' }}} but the top-level declaration syntax of these languages is easier. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12146#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12146: syntax repair suggestion is too eager to suggest TemplateHaskell -------------------------------------+------------------------------------- Reporter: j.waldmann | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by adityadivekar): Hi, I've just started looking at the GHC source. I would like to work on this issue if its still up for grabs. If yes, it seems the error message needs to changed to something like `Parse error: module header, import declaration or top-level declaration expected` and the suggestion needs to be removed. The error text is defined in `RnSource.hs` in the field `badImplicitSplice` and is displayed in case of an `ImplicitSplice` if I'm right. Could you help me in going around this issue? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12146#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12146: syntax repair suggestion is too eager to suggest TemplateHaskell -------------------------------------+------------------------------------- Reporter: j.waldmann | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by adityadivekar): * Attachment "0001-Correct-the-message-displayed-for-syntax-error.patch" added. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12146 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

Of course, these are only heuristics so there will be false-positive and false-negative cases. But I think these heuristics will help more than
#12146: syntax repair suggestion is too eager to suggest TemplateHaskell -------------------------------------+------------------------------------- Reporter: j.waldmann | Owner: Type: feature request | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #7396 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by thomie): * status: new => patch * related: => #7396 Comment: You'll have to update the expected output for some tests as well, see [wiki:Building/RunningTests]. Also have a look at #7396, where the current error message was decided: they will hurt. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12146#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12146: syntax repair suggestion is too eager to suggest TemplateHaskell -------------------------------------+------------------------------------- Reporter: j.waldmann | Owner: Type: feature request | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #7396 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by adityadivekar): So in some cases, as described in #7396, it is desirable to have the message suggesting TemplateHaskell. The expected stderr for test cases T6106 and T1914 in `/ghci/scripts` can be modified as per the suggestion in the patch I uploaded. But the script for test T4042 in `/rename/should_fail`clearly expects the TemplateHaskell suggestion in stderr (as mentioned in the comments in the test case script). So changing the message would invalidate the test case. I'm not sure how to handle this conflict. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12146#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12146: syntax repair suggestion is too eager to suggest TemplateHaskell -------------------------------------+------------------------------------- Reporter: j.waldmann | Owner: Type: feature request | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #7396 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by thomie): #7396 made 3 changes. The parser error message should suggest `TemplateHaskell` when a module contains at the toplevel: * `$foo` * `bar = 3 + $(x)` * `foo` The first two of those are fine. The third one is to handle this bit of obscure TemplateHaskell syntax:
You may omit the $(...) in a top-level declaration splice. Simply writing an expression (rather than a declaration) implies a splice.
The number of TemplateHaskell users who write modules using //only// this syntax, but who forget to add `LANGUAGE TemplateHaskell`, and who get confused about the new error message, should be much much smaller than those who get confused about the current error message for `ipmort Data.Monoid`. Furthermore, the comment in `T4042.hs` says that implicit splices without `-XTemplateHaskell` shouldn't lead to out of scope errors. Your new error message fits that criteria. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12146#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12146: syntax repair suggestion is too eager to suggest TemplateHaskell -------------------------------------+------------------------------------- Reporter: j.waldmann | Owner: Type: feature request | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #7396 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by adityadivekar): * Attachment "0001-Change-the-expected-stderr-output-of-tests.patch" added. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12146 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12146: syntax repair suggestion is too eager to suggest TemplateHaskell -------------------------------------+------------------------------------- Reporter: j.waldmann | Owner: Type: feature request | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #7396 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by adityadivekar): * Attachment "0001-Add-test-case-for-ticket-12146.patch" added. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12146 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12146: syntax repair suggestion is too eager to suggest TemplateHaskell -------------------------------------+------------------------------------- Reporter: j.waldmann | Owner: Type: feature request | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #7396 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by adityadivekar): Thanks for the above help. So that means the test case `T4042.hs` stderr can be validly changed to the new stderr since it falls into the third category i.e. `foo`. Also I've added a test case with misspelled `ipmort` as described in the ticket. Kindly let me know the review. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12146#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12146: syntax repair suggestion is too eager to suggest TemplateHaskell
-------------------------------------+-------------------------------------
Reporter: j.waldmann | Owner:
Type: feature request | Status: patch
Priority: normal | Milestone:
Component: Compiler | Version: 8.0.1
Resolution: | Keywords: newcomer
Operating System: Unknown/Multiple | Architecture:
Type of failure: Incorrect | Unknown/Multiple
warning at compile-time | Test Case:
Blocked By: | Blocking:
Related Tickets: #7396 | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Thomas Miedema

#12146: syntax repair suggestion is too eager to suggest TemplateHaskell -------------------------------------+------------------------------------- Reporter: j.waldmann | Owner: Type: feature request | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #7396 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by thomie): adityadivekar: I pushed the first two patches, but the last one did not apply cleanly to HEAD. The testcase also seems unnecessarily complicated (I guess you copied it from another test, but I don't understand why this hack is necessary): {{{ :set -v1 System.IO.writeFile "T12146.hs" "module Main where { ipmort Data.Char; }" -- hack: avoid the need for sleep by using specific timestamps: :! touch -t 01010000 T12146.hs :load T12146 }}} Two things are still missing: * a simple `compile_fail` test. Use `T4042` as an example. * a small comment for `badImplicitSplice` (`compiler/rename/RnSource.hs`), explaining why the error messages shouldn't mention `TemplateHaskell`, referring to this ticket (#12146). If you could, please create a new patch for this, and I'll apply it. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12146#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12146: syntax repair suggestion is too eager to suggest TemplateHaskell -------------------------------------+------------------------------------- Reporter: j.waldmann | Owner: Type: feature request | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #7396 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by adityadivekar): Yes, I realised that the hack was unnecessary. I'm sorry for that. I've simplified it now. And I've created two new patches - one containing the comment about `badImplicitSplice`, and the other containing the two test cases. I thought it would be confusing to put them in one patch, so I split them. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12146#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12146: syntax repair suggestion is too eager to suggest TemplateHaskell -------------------------------------+------------------------------------- Reporter: j.waldmann | Owner: Type: feature request | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #7396 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by adityadivekar): * Attachment "0001-Add-comment-explaining-change-in-syntax-error- sugges.patch" added. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12146 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12146: syntax repair suggestion is too eager to suggest TemplateHaskell -------------------------------------+------------------------------------- Reporter: j.waldmann | Owner: Type: feature request | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #7396 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by adityadivekar): * Attachment "0001-Add-test-cases-for-Ticket-12146.patch" added. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12146 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12146: syntax repair suggestion is too eager to suggest TemplateHaskell -------------------------------------+------------------------------------- Reporter: j.waldmann | Owner: Type: feature request | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #7396 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by adityadivekar): thomie: ping regarding the patch. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12146#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12146: syntax repair suggestion is too eager to suggest TemplateHaskell -------------------------------------+------------------------------------- Reporter: j.waldmann | Owner: (none) Type: feature request | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #7396 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by thomie): @adityadivekar: I submitted a pull for your patches. https://github.com/ghc/ghc/pull/181. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12146#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12146: syntax repair suggestion is too eager to suggest TemplateHaskell
-------------------------------------+-------------------------------------
Reporter: j.waldmann | Owner: (none)
Type: feature request | Status: patch
Priority: normal | Milestone:
Component: Compiler | Version: 8.0.1
Resolution: | Keywords: newcomer
Operating System: Unknown/Multiple | Architecture:
Type of failure: Incorrect | Unknown/Multiple
warning at compile-time | Test Case:
Blocked By: | Blocking:
Related Tickets: #7396 | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#12146: syntax repair suggestion is too eager to suggest TemplateHaskell
-------------------------------------+-------------------------------------
Reporter: j.waldmann | Owner: (none)
Type: feature request | Status: patch
Priority: normal | Milestone:
Component: Compiler | Version: 8.0.1
Resolution: | Keywords: newcomer
Operating System: Unknown/Multiple | Architecture:
Type of failure: Incorrect | Unknown/Multiple
warning at compile-time | Test Case:
Blocked By: | Blocking:
Related Tickets: #7396 | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#12146: syntax repair suggestion is too eager to suggest TemplateHaskell -------------------------------------+------------------------------------- Reporter: j.waldmann | Owner: (none) Type: feature request | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: fixed | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #7396 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by monoidal): * status: patch => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12146#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC