[GHC] #13834: Error cascade with type applications

#13834: Error cascade with type applications -------------------------------------+------------------------------------- Reporter: mpickering | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Keywords: newcomer, | Operating System: Unknown/Multiple TypeApplications | Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Using type applications with an out of scope identifier causes an unfortunate error cascade. {{{ foo = notInScope @Bool }}} Leads to the right out of scope error but also an error about using type application when `notInScope` is not a polytype. I think the second error should be suppressed. {{{ t.hs:4:7: error: Variable not in scope: notInScope | 4 | foo = notInScope @Bool | ^^^^^^^^^^ t.hs:4:7: error: • Cannot apply expression of type ‘t1’ to a visible type argument ‘Bool’ notInScope • In the expression: notInScope @Bool In an equation for ‘foo’: foo = notInScope @Bool | 4 | foo = notInScope @Bool | ^^^^^^^^^^^^^^^^ }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13834 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13834: Error cascade with type applications -------------------------------------+------------------------------------- Reporter: mpickering | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: newcomer, | TypeApplications Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Trac #13834 Here is what is happening: * The `Cannot apply expression..." error is spat out immediately, during constraint generation, not by `TcErrors` * The `Variable not in scope..` error is deferred; we spit out a constraint (a `CHoleCan` in fact). The constraint solver does its work; doing so will not solve the `CHoleCan`, but it often /does/ figure out what type the out-of-scope variable should have. The error is finally reported by `TcErrors`, when it reports errors from unsolved constraints Fixing this would be possible but fiddly. The obvious thing would be to add a new form of constraint, or generalise `CHoleCan`, to allow the "Cannot apply" error to be deferred. Then the error-message-prioritisation scheme in `TcErrors` could give the out-of-scope error priority over the cannot-apply one. If we did this, it should probably be just part of a generic way of deferring error messages. There are othe errors that are spat out immediately rather than going through the constraint solver. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13834#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13834: Error cascade with type applications -------------------------------------+------------------------------------- Reporter: mpickering | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: newcomer, | TypeApplications, TypeErrorMessages Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * keywords: newcomer, TypeApplications => newcomer, TypeApplications, TypeErrorMessages -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13834#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13834: Error cascade with type applications -------------------------------------+------------------------------------- Reporter: mpickering | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: | TypeApplications, TypeErrorMessages Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by goldfire): * keywords: newcomer, TypeApplications, TypeErrorMessages => TypeApplications, TypeErrorMessages Comment: If I'm daunted by fixing it, it's not for a newcomer. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13834#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13834: Error cascade with type applications -------------------------------------+------------------------------------- Reporter: mpickering | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: | TypeApplications, TypeErrorMessages Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #12794 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * related: => #12794 Comment: See #12794 for the `-fdefer-type-errors` version of this issue. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13834#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13834: Error cascade with type applications -------------------------------------+------------------------------------- Reporter: mpickering | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: | TypeApplications, TypeErrorMessages Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #12794 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): As dbaynard noted in https://ghc.haskell.org/trac/ghc/ticket/12092#comment:4, things are even worse on GHC 8.6 than they used to be. That is, while you'd get these errors on GHC 8.4.4: {{{ $ /opt/ghc/8.4.4/bin/ghc -XTypeApplications -e "notInScope @Bool" <interactive>:0:1: error: Variable not in scope: notInScope <interactive>:0:1: error: • Cannot apply expression of type ‘t1’ to a visible type argument ‘Bool’ • In the expression: notInScope @Bool In an equation for ‘it’: it = notInScope @Bool }}} You don't even get the `Variable not in scope` error on GHC 8.6.3: {{{ $ /opt/ghc/8.6.3/bin/ghc -XTypeApplications -e "notInScope @Bool" <interactive>:0:1: error: • Cannot apply expression of type ‘t1’ to a visible type argument ‘Bool’ • In the expression: notInScope @Bool In an equation for ‘it’: it = notInScope @Bool }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13834#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13834: Error cascade with type applications -------------------------------------+------------------------------------- Reporter: mpickering | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: | TypeApplications, TypeErrorMessages Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #12794 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): Ah, but the regression has disappeared on GHC HEAD! {{{ $ ghc4/inplace/bin/ghc-stage2 -XTypeApplications -e "notInScope @Bool" <interactive>:0:1: error: Variable not in scope: notInScope <interactive>:0:1: error: • Cannot apply expression of type ‘t1’ to a visible type argument ‘Bool’ • In the expression: notInScope @Bool In an equation for ‘it’: it = notInScope @Bool }}} So... false alarm? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13834#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13834: Error cascade with type applications -------------------------------------+------------------------------------- Reporter: mpickering | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: | TypeApplications, TypeErrorMessages Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #12794 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Well * I think it'd be better to suppress the "Cannot apply" error. That is what the origina ticket Description was asking for, and I think I can see how to do so. (Suppress the error in `TcExpr.tcArgs` if the `fun` is a `HsUnboundVar`.) * But a harder problem is that if you try with `-fdefer-type-errors` then we get {{{ bash$ ghc -c T13834.hs -fdefer-type-errors T13834.hs:5:7: error: • Cannot apply expression of type ‘t1’ to a visible type argument ‘Bool’ • In the expression: notInScope @Bool In an equation for ‘foo’: foo = notInScope @Bool | 5 | foo = notInScope @Bool | ^^^^^^^^^^^^^^^^ }}} The out-of-scope thing has turned into a warning, with deferred evidence. And rightly so in a way: you can run a program with an out-of- scope variable, provided you don't evaluate it. But the "cannot apply" error is still an error: it can't be deferred. I have not thought deeply about this, but I can't see an easy fix. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13834#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13834: Error cascade with type applications -------------------------------------+------------------------------------- Reporter: mpickering | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: | TypeApplications, TypeErrorMessages Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #12794 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): Sure, I didn't want to suggest that this ticket was fixed completely, only that the particular buglet that the `Variable not in scope` message disappearing (without `-fdefer-type-errors`) had been fixed. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13834#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC