Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

#1204 closed bug (fixed)

Associated types don't work with record updates

Reported by: nominolo@… Owned by:
Priority: normal Milestone: 6.8.1
Component: Compiler (Type checker) Version: 6.7
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Test Case: Records.hs
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description

(I couldn't find a more descriptive title, feel free to change it)
When instantiating associated types with records, record update doesn't seem to work (at least in indirect uses). I think it should. If this is supposed to fail, then a more helpful error message might be very useful.

Here's the code:

{-# OPTIONS -findexed-types #-}
module Bug where

------------------------------------------------------------------------------

class C c where
  data D1 c

class C c => D c where
  works :: Int -> D1 c -> D1 c
  buggy :: Int -> D1 c -> D1 c 
  buggy2 :: Int -> D1 c -> D1 c

------------------------------------------------------------------------------

data FooC = FooC

instance C FooC where
  data D1 FooC = D1F { moo :: Int }
  
instance D FooC where
  works x d = d  -- d unchanged, so OK

  buggy x d@(D1F { moo = k }) = 
    d { moo = k + x }  -- d is updated wrong type--why?

  buggy2 x d@(D1F { moo = k }) =
    (d :: D1 FooC) { moo = k + x } -- type annotation doesn't work

GHC Output:

$ ghc67 -v -c Bug67.hs
Glasgow Haskell Compiler, Version 6.7.20070303, for Haskell 98, compiled by GHC version 6.7.20070303
Using package config file: /usr/local/lib/ghc-6.7.20070303/package.conf
wired-in package base mapped to base-2.0
wired-in package rts mapped to rts-1.0
wired-in package haskell98 mapped to haskell98-1.0
wired-in package template-haskell mapped to template-haskell-2.0
Hsc static flags: -static
Created temporary directory: /tmp/ghc422_0
*** Checking old interface for main:Bug:
*** Parser:
*** Renamer/typechecker:

Bug67.hs:25:4:
    Couldn't match expected type `D1 FooC'
	   against inferred type `(Bug.:R2D1)'
    In the expression: d {moo = k + x}
    In the definition of `buggy':
	buggy x (d@(D1F {moo = k})) = d {moo = k + x}
    In the definition for method `buggy'

Bug67.hs:28:4:
    Couldn't match expected type `D1 FooC'
	   against inferred type `(Bug.:R2D1)'
    In the expression: (d :: D1 FooC) {moo = k + x}
    In the definition of `buggy2':
	buggy2 x (d@(D1F {moo = k})) = (d :: D1 FooC) {moo = k + x}
    In the definition for method `buggy2'

Change History (5)

comment:1 Changed 8 years ago by igloo

  • Component changed from Compiler to Compiler (Type checker)
  • Milestone set to 6.8

comment:2 Changed 8 years ago by simonpj

  • Resolution set to fixed
  • Status changed from new to closed
  • Test Case set to Records.hs

Good bug repoort. I have finally found a moment to fix it. Should work now.

Simon

comment:3 Changed 8 years ago by igloo

  • Milestone changed from 6.8 branch to 6.8.1

comment:4 Changed 7 years ago by simonmar

  • Architecture changed from Unknown to Unknown/Multiple

comment:5 Changed 7 years ago by simonmar

  • Operating System changed from Unknown to Unknown/Multiple
Note: See TracTickets for help on using tickets.