Opened 3 years ago

Closed 16 months ago

Last modified 8 months ago

#12092 closed bug (fixed)

Out-of-scope variable leads to type error, not scope error

Reported by: kwf Owned by:
Priority: normal Milestone:
Component: Compiler (Type checker) Version: 8.0.1
Keywords: TypeApplications Cc: goldfire
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect warning at compile-time Test Case:
Blocked By: Blocking:
Related Tickets: #13834 Differential Rev(s):
Wiki Page:

Description

When I write the following:

{-# language TypeApplications #-}

module Bug where

huh = spam @Int

I expect to get the error:

    • Variable not in scope: spam
    • Perhaps you meant ‘span’ (imported from Prelude)

But instead, I get the error:

    • Cannot apply expression of type ‘t0’
      to a visible type argument ‘Int’
    • In the expression: spam @Int
      In an equation for ‘huh’: huh = spam @Int

While it is technically true that I cannot apply an out-of-scope identifier to a visible type argument, this is probably the less useful error to receive.

Change History (5)

comment:1 Changed 3 years ago by goldfire

This is actually representative of a class of suboptimal errors that I've seen while working with GHC 8, in that an out-of-scope identifier can cause a cascade of obscure type errors. Perhaps we should prioritize out-of-scope identifiers above other type errors.

comment:2 Changed 3 years ago by goldfire

Summary: Wrong error message with TypeApplicationsOut-of-scope variable leads to type error, not scope error

Changing the description of the ticket so that it doesn't look like my fault. :)

comment:3 Changed 16 months ago by RyanGlScott

Keywords: TypeApplications added
Resolution: fixed
Status: newclosed

In GHC 8.4, you do in fact get a "Variable not in scope" error:

Bug.hs:5:7: error:
    • Variable not in scope: spam
    • Perhaps you meant ‘span’ (imported from Prelude)
  |
5 | huh = spam @Int
  |       ^^^^

Bug.hs:5:7: error:
    • Cannot apply expression of type ‘t1’
      to a visible type argument ‘Int’
    • In the expression: spam @Int
      In an equation for ‘huh’: huh = spam @Int
  |
5 | huh = spam @Int
  |       ^^^^^^^^^

Of course, there's still the issue that the second part of the error message still appears. But that is the subject of #13834, so I'll close this ticket in favor of that one.

comment:4 Changed 8 months ago by dbaynard

I'm seeing this on 8.6.3 (even with -fno-defer-type-errors). Note: my ghc install is managed by stack.

Without application

> cat type-app-err.hs
{-# LANGUAGE TypeApplications #-}

module Bug where

huh = spam

> ghc -fno-defer-type-errors type-app-err                                                                                              16:19:10
[1 of 1] Compiling Bug              ( type-app-err.hs, type-app-err.o )

type-app-err.hs:5:7: error:
    • Variable not in scope: spam
    • Perhaps you meant ‘span’ (imported from Prelude)
  |
5 | huh = spam
  |       ^^^^

Without application

> cat type-app-err.hs
{-# LANGUAGE TypeApplications #-}

module Bug where

huh = spam @Int

> ghc -fno-defer-type-errors type-app-err                                                                                              16:19:18
[1 of 1] Compiling Bug              ( type-app-err.hs, type-app-err.o )

type-app-err.hs:5:7: error:
    • Cannot apply expression of type ‘t1’
      to a visible type argument ‘Int’
    • In the expression: spam @Int
      In an equation for ‘huh’: huh = spam @Int
  |
5 | huh = spam @Int
  |       ^^^^^^^^^

comment:5 Changed 8 months ago by RyanGlScott

Oh dear, that is a good observation. It seems that this has regressed at some point between 8.4 and 8.6.

Since #13834 is basically the same issue, let's move the discussion about this problem to there.

Note: See TracTickets for help on using tickets.