Don't skip validity checks for built-in classes (#17355)
[ghc.git] / testsuite / tests / typecheck / should_compile / tc199.hs
1 {-# LANGUAGE MultiParamTypeClasses, AllowAmbiguousTypes #-}
2
3 -- This code defines a default method with a highly dubious type,
4 -- because 'v' is not mentioned, and there are no fundeps
5 -- Hence needing AllowAmbiguousTypes
6 --
7 -- However, arguably the instance declaration should be accepted,
8 -- beause it's equivalent to
9 -- instance Baz Int Int where { foo x = x }
10 -- which *does* typecheck
11
12 -- GHC does not actually macro-expand the instance decl. Instead, it
13 -- defines a default method function, thus
14 --
15 -- $dmfoo :: Baz v x => x -> x
16 -- $dmfoo y = y
17 --
18 -- Notice that this is an ambiguous type: you can't call $dmfoo
19 -- without triggering an error. And when you write an instance decl,
20 -- it calls the default method:
21 --
22 -- instance Baz Int Int where foo = $dmfoo
23 --
24 -- I'd never thought of that. You might think that we should just
25 -- *infer* the type of the default method (here forall a. a->a), but
26 -- in the presence of higher rank types etc we can't necessarily do
27 -- that.
28
29 module Foo1 where
30
31 class Baz v x where
32 foo :: x -> x
33 foo y = y
34
35 instance Baz Int Int