Opened 3 months ago

Closed 8 weeks ago

Last modified 8 weeks ago

#13947 closed bug (fixed)

GHC 8.2 gives misleading error message for out-of-scope infix type constructor

Reported by: RyanGlScott Owned by: RyanGlScott
Priority: normal Milestone: 8.2.2
Component: Compiler Version: 8.2.1-rc2
Keywords: ORF Cc: adamgundry
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Poor/confusing error message Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D3718
Wiki Page:

Description

{-# LANGUAGE TypeOperators #-}
module Bug where

f :: () -> Int :~: Int
f = undefined

GHC 8.0.2 gives a reasonable error message:

$ /opt/ghc/8.0.2/bin/ghc Bug.hs
[1 of 1] Compiling Bug              ( Bug.hs, Bug.o )

Bug.hs:4:12: error: Not in scope: type constructor or class ‘:~:’

But GHC 8.2.1's error message is much more confusing:

$ /opt/ghc/8.2.1/bin/ghc Bug.hs
[1 of 1] Compiling Bug              ( Bug.hs, Bug.o )

Bug.hs:4:6: error:
    Precedence parsing error
        cannot mix ‘(->)’ [infixr 0] and ‘:~:’ [infixl 0] in the same infix expression
  |
4 | f :: () -> Int :~: Int
  |      ^^^^^^^^^^^^^^^^^

Bug.hs:4:12: error:
    Not in scope: type constructor or class ‘:~:’
    A data constructor of that name is in scope; did you mean DataKinds?
  |
4 | f :: () -> Int :~: Int
  |            ^^^^^^^^^^^

I was thrown akilter by the claim that :~: was infixl 0, since it was displayed before the real cause of the error (that it's out-of-scope). Adding import Data.Type.Equality fixes the error, but GHC really shouldn't be making claims about the fixities of out-of-scope type constructors in the first place.

Change History (8)

comment:1 Changed 3 months ago by RyanGlScott

Cc: adamgundry added

This started occurring in commit 2484d4dae65c81f218dcfe494b963b2630bb8fa6 (Refactor renaming of operators/sections to fix DuplicateRecordFields bugs).

comment:2 Changed 3 months ago by adamgundry

Keywords: ORF added

comment:3 Changed 3 months ago by RyanGlScott

Owner: set to RyanGlScott

After skimming the commitdiff, I'm reasonably confident I know what is happening, and how fix it. I'll post a Phab Diff after I've validated.

Also, I just realized that there's another problem with the error message in GHC 8.2: it claims that a constructor :~: is in scope, but that's untrue. I'll submit a separate ticket for this later.

comment:4 Changed 3 months ago by RyanGlScott

Differential Rev(s): Phab:D3718
Status: newpatch

comment:5 Changed 3 months ago by RyanGlScott

I've opened #13948 for the A data constructor of that name is in scope issue.

comment:6 Changed 3 months ago by Ben Gamari <ben@…>

In 85ac65c/ghc:

Fix #13947 by checking for unbounded names more

Commit 2484d4dae65c81f218dcfe494b963b2630bb8fa6 accidentally dropped a
call to `isUnboundName` in an important location. This re-adds it.

Fixes #13947.

Test Plan: make test TEST=T13947

Reviewers: adamgundry, austin, bgamari

Reviewed By: adamgundry

Subscribers: rwbarton, thomie

GHC Trac Issues: #13947

Differential Revision: https://phabricator.haskell.org/D3718

comment:7 Changed 3 months ago by bgamari

Milestone: 8.2.2
Status: patchmerge

comment:8 Changed 8 weeks ago by bgamari

Resolution: fixed
Status: mergeclosed
Last edited 8 weeks ago by bgamari (previous) (diff)
Note: See TracTickets for help on using tickets.