summaryrefslogtreecommitdiff
path: root/testsuite/tests/indexed-types/should_compile/Records.hs
blob: 4a08125e300bd6c435a85a96f2957931dadf46ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
{-# LANGUAGE TypeFamilies #-}

-- See Trac #1204

module ShouldCompile where

data FooC = FooC

data family T c
data instance T FooC = MkT { moo :: Int }

t1 :: Int -> T FooC
t1 i = MkT { moo = i }

t2 :: T FooC -> Int
t2 (MkT { moo = i }) = i

t3 :: T FooC -> Int
t3 m = moo m

f :: T FooC -> T FooC
f r = r { moo = 3 }


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

instance D FooC where
  data D1 FooC = D1F { noo :: Int }

  works x d = d  -- d unchanged, so OK

  buggy x d@(D1F { noo = k }) = 
    d { noo = k + x }

  buggy2 x d@(D1F { noo = k }) =
    (d :: D1 FooC) { noo = k + x }