Commit f9007960 authored by twanvl's avatar twanvl Committed by Herbert Valerio Riedel

Tests for MINIMAL pragma (#7633)

parent b6d90d10
TOP=../..
include $(TOP)/mk/boilerplate.mk
include $(TOP)/mk/test.mk
TOP=../../..
include $(TOP)/mk/boilerplate.mk
include $(TOP)/mk/test.mk
module WarnMinimal where
class Fine a where
instance Fine Int
-------------------
class Foo a where
foo1 :: a
foo2 :: a
foo1 = foo2
foo2 = foo1
{-# MINIMAL foo1 | foo2 #-}
-- this should generate a warning
instance Foo Int where -- WARNING LINE
-- this should generate no warning
instance Foo Char where
foo1 = 'x'
-- nor should this
instance Foo Bool where
foo2 = True
instance Foo Double where
foo1 = 1
foo2 = 2
-------------------
class Monad' f where
return' :: a -> f a
fmap' :: (a -> b) -> f a -> f b
join' :: f (f a) -> f a
bind' :: f a -> (a -> f b) -> f b
{-# MINIMAL return', (fmap',join' | bind') #-}
fmap' f x = bind' x (return' . f)
join' x = bind' x id
bind' x f = join' (fmap' f x)
instance Monad' [] where
return' = return
fmap' = map
join' = concat
-- no warning
instance Monad' Maybe where
return' = Just
bind' = (>>=)
-- no warning
instance Monad' IO where
return' = return
bind' = (>>=)
fmap' = fmap
join' = (>>= id)
-- no warning
instance Monad' ((->) e) where -- WARNING LINE
return' = const
fmap' = (.)
-- warning!
newtype Id a = Id a
instance Monad' Id where -- WARNING LINE
fmap' f (Id x) = Id (f x)
join' (Id x) = x
-- warning!
newtype Id2 a = Id2 a
instance Monad' Id2 where -- WARNING LINE
fmap' f (Id2 x) = Id2 (f x)
join' (Id2 x) = x
bind' (Id2 x) f = f x
-- warning!
newtype Id3 a = Id3 a
instance Monad' Id3 where -- WARNING LINE
---------
-- incorrect minimal spec
class Cheater a where -- WARNING LINE
cheater :: a
{-# MINIMAL #-} -- warning!
class Cheater2 a where
_cheater2 :: a
{-# MINIMAL #-} -- no warning
class Cheater3 a where -- WARNING LINE
cheater3, cheater3b :: a
{-# MINIMAL cheater3 #-} -- warning!
---------
-- new style warning for classes without explicit spec
instance Num Bool where -- WARNING LINE
class NoExplicit a where
needed :: a
_optional :: a
instance NoExplicit Int where -- WARNING LINE
---------
data Blarg = Blarg
class Eq' a where
(===) :: a -> a -> Bool
(/==) :: a -> a -> Bool
x === y = not (x /== y)
x /== y = not (x === y)
{-# MINIMAL (===) | (/==) #-}
instance Eq' Blarg where -- WARNING LINE
WarnMinimal.hs:16:10: Warning:
No explicit implementation for
either ‛foo1’ or ‛foo2’
In the instance declaration for ‛Foo Int’
WarnMinimal.hs:60:10: Warning:
No explicit implementation for
either ‛join'’ or ‛bind'’
In the instance declaration for ‛Monad' ((->) e)’
WarnMinimal.hs:66:10: Warning:
No explicit implementation for
‛return'’
In the instance declaration for ‛Monad' Id’
WarnMinimal.hs:72:10: Warning:
No explicit implementation for
‛return'’
In the instance declaration for ‛Monad' Id2’
WarnMinimal.hs:79:10: Warning:
No explicit implementation for
‛return'’ and (either (‛fmap'’ and ‛join'’) or ‛bind'’)
In the instance declaration for ‛Monad' Id3’
WarnMinimal.hs:84:1: Warning:
The MINIMAL pragma does not require:
‛cheater’
but there is no default implementation.
In the class declaration for ‛Cheater’
WarnMinimal.hs:92:1: Warning:
The MINIMAL pragma does not require:
‛cheater3b’
but there is no default implementation.
In the class declaration for ‛Cheater3’
WarnMinimal.hs:99:10: Warning:
No explicit implementation for
‛+’, ‛*’, ‛abs’, ‛signum’, and ‛fromInteger’
In the instance declaration for ‛Num Bool’
WarnMinimal.hs:105:10: Warning:
No explicit implementation for
‛needed’
In the instance declaration for ‛NoExplicit Int’
WarnMinimal.hs:116:10: Warning:
No explicit implementation for
either ‛===’ or ‛/==’
In the instance declaration for ‛Eq' Blarg’
module WarnMinimalFail1 where
global :: Int
global = 0
{-# MINIMAL global #-} -- invalid, should only be used inside a class declaration
WarnMinimalFail1.hs:5:1:
Misplaced MINIMAL pragma: {-# MINIMAL global #-}
module WarnMinimalFail2 where
global :: Int
global = 0
class Foo a where
local :: a
{-# MINIMAL global #-}
WarnMinimalFail2.hs:8:15:
‛global’ is not a (visible) method of class ‛Foo’
{-# LANGUAGE DefaultSignatures #-}
module WarnMinimalFail3 where
class Parent a where
parent :: a
default parent :: Child a => a
parent = child
class Parent a => Child a where
child :: a
child = parent
{-# MINIMAL parent | child #-}
-- we would like this to work, but it doesn't yet.
WarnMinimalFail3.hs:12:15:
‛parent’ is not a (visible) method of class ‛Child’
test('WarnMinimal', normal, compile, [''])
test('WarnMinimalFail1', normal, compile_fail, [''])
test('WarnMinimalFail2', normal, compile_fail, [''])
test('WarnMinimalFail3', normal, compile_fail, [''])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment