Opened 3 months ago

Last modified 3 months ago

#13834 new bug

Error cascade with type applications

Reported by: mpickering Owned by:
Priority: normal Milestone:
Component: Compiler Version: 8.0.1
Keywords: TypeApplications, TypeErrorMessages Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown 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
  |       ^^^^^^^^^^^^^^^^

Change History (3)

comment:1 Changed 3 months ago by simonpj

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.

Last edited 3 months ago by simonpj (previous) (diff)

comment:2 Changed 3 months ago by simonpj

Keywords: TypeErrorMessages added

comment:3 Changed 3 months ago by goldfire

Keywords: newcomer removed

If I'm daunted by fixing it, it's not for a newcomer.

Note: See TracTickets for help on using tickets.