Opened 4 weeks ago

Closed 11 days ago

#15308 closed bug (fixed)

Error message prints explicit kinds when it shouldn't

Reported by: RyanGlScott Owned by:
Priority: normal Milestone: 8.6.1
Component: Compiler (Type checker) Version: 8.4.3
Keywords: TypeInType Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Poor/confusing error message Test Case: dependent/should_fail/T15308
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D4891
Wiki Page:

Description

When compiled, this program:

{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeInType #-}
{-# OPTIONS_GHC -fno-print-explicit-kinds #-}
module Bug where

import Data.Kind

data Foo (a :: Type) :: forall b. (a -> b -> Type) -> Type where
  MkFoo :: Foo a f

f :: Foo a f -> String
f = show

Gives the following error:

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

Bug.hs:13:5: error:
    • No instance for (Show (Foo a b f)) arising from a use of ‘show’
    • In the expression: show
      In an equation for ‘f’: f = show
   |
13 | f = show
   |     ^^^^

This error message is slightly incorrect, however. In "No instance for (Show (Foo a b f))", it claims that Foo has three visible type parameters, but it only has two. (I've even made sure to enable -fno-print-explicit-kinds at the type to ensure that the invisible b kind shouldn't get printed, but it was anyway.)

This is a regression that was apparently introduced between GHC 8.0 and 8.2, since in GHC 8.0.2, it prints the correct thing:

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

Bug.hs:13:5: error:
    • No instance for (Show (Foo a f)) arising from a use of ‘show’
    • In the expression: show
      In an equation for ‘f’: f = show

But it does not in GHC 8.2.1:

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

Bug.hs:13:5: error:
    • No instance for (Show (Foo a b f)) arising from a use of ‘show’
    • In the expression: show
      In an equation for ‘f’: f = show
   |
13 | f = show
   |     ^^^^

Change History (5)

comment:1 Changed 4 weeks ago by RyanGlScott

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

comment:2 Changed 4 weeks ago by Simon Peyton Jones <simonpj@…>

In 3d00208/ghc:

Add commnent about binder order

...provoked by Trac #15308

comment:3 Changed 3 weeks ago by Ryan Scott <ryan.gl.scott@…>

In 93b7ac8/ghc:

Fix #15308 by suppressing invisble args more rigorously

Summary:
There was a buglet in `stripInvisArgs` (which is part of the
pretty-printing pipeline for types) in which only invisble arguments
which came before any visible arguments would be suppressed, but any
invisble arguments that came //after// visible ones would still be
printed, even if `-fprint-explicit-kinds`  wasn't enabled.
The fix is simple: make `stripInvisArgs` recursively process the
remaining types even after a visible argument is encountered.

Test Plan: make test TEST=T15308

Reviewers: goldfire, bgamari

Reviewed By: bgamari

Subscribers: simonpj, rwbarton, thomie, carter

GHC Trac Issues: #15308

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

comment:4 Changed 3 weeks ago by RyanGlScott

Status: patchmerge
Test Case: dependent/should_fail/T15308

comment:5 Changed 11 days ago by bgamari

Resolution: fixed
Status: mergeclosed
Note: See TracTickets for help on using tickets.