Opened 5 years ago

Closed 5 years ago

#3176 closed bug (fixed)

erroneous defaulting? behaviour for existentials

Reported by: claus Owned by:
Priority: normal Milestone:
Component: Compiler Version: 6.11
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: typecheck/should_fail/T3176 Blocked By:
Blocking: Related Tickets:

Description

consider

{-# LANGUAGE NoExtendedDefaultRules #-}
{-# OPTIONS_GHC -fwarn-type-defaults #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ExistentialQuantification #-}

data EShow = forall a. Show a => EShow a

smallPrint t = concatMap (\f-> case f t of EShow a -> show a) [EShow . foo, EShow . bar, EShow . baz]

data ES = forall a. Show a => ES {unES:: a}

smallPrintES t = concatMap (\f-> show $ unES $ f t) [ES . foo, ES . bar, ES . baz]

data Test = Test { foo :: Int, bar :: Char, baz :: Bool }

main = print $ smallPrintES $ Test 1 'x' False

for which

$ /cygdrive/c/ghc/ghc-6.11.20090320/bin/ghc -e "main" exists.hs
"()()()"

while

$ /cygdrive/c/ghc/ghc-6.8.3/bin/ghc -e "main" exists.hs

exists.hs:12:40:
    Cannot use record selector `unES' as a function due to escaped type variables
    Probably fix: use pattern-matching syntax instead
    In the first argument of `($)', namely `unES'
    In the second argument of `($)', namely `unES $ f t'
    In the expression: show $ unES $ f t

The expected results were error message or this

$ /cygdrive/c/ghc/ghc-6.11.20090320/bin/ghc -e "smallPrint $ Test 1 'x' False" exists.hs
"1'x'False"

There seem to be two issues:

  • shouldn't ghc head report the use of unES as an error?
  • how does ghc head arrive at that result, with these flags, without any warnings?

Change History (1)

comment:1 Changed 5 years ago by simonpj

  • Difficulty set to Unknown
  • Resolution set to fixed
  • Status changed from new to closed
  • Test Case set to typecheck/should_fail/T3176

Thank you. A definite bug caused by some earlier fiddling with record selectors. Fixed by

Thu Apr 23 02:42:37 PDT 2009  simonpj@microsoft.com
  * Fix Trac #3176: intercept naughty record selectors

  When making record selectors into ordinary functions (rather than
  magial implicit Ids) I forgot that they could therefore show up in
  the *local* TcEnv, not the global one.  This fixes that problem,
  and thereby Trac #3176.

I added a test case too.

Smon

Note: See TracTickets for help on using tickets.