Tests for nullary type classes (#7642)
authorKrzysztof Gogolewski <krz.gogolewski@gmail.com>
Mon, 11 Mar 2013 12:32:58 +0000 (13:32 +0100)
committerSimon Peyton Jones <simonpj@microsoft.com>
Wed, 13 Mar 2013 21:11:01 +0000 (21:11 +0000)
testsuite/tests/driver/T4437.hs
testsuite/tests/typecheck/should_fail/TcNoNullaryTC.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/TcNoNullaryTC.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/TcNullaryTCFail.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/TcNullaryTCFail.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/all.T
testsuite/tests/typecheck/should_run/TcNullaryTC.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_run/TcNullaryTC.stdout [new file with mode: 0644]
testsuite/tests/typecheck/should_run/all.T

index 617484c..cb1d5f8 100644 (file)
@@ -39,7 +39,8 @@ expectedGhcOnlyExtensions = [
                              "TypeHoles",
                              "OverloadedLists",
                              "EmptyCase",
-                             "AutoDeriveTypeable"]
+                             "AutoDeriveTypeable",
+                             "NullaryTypeClasses"]
 
 expectedCabalOnlyExtensions :: [String]
 expectedCabalOnlyExtensions = ["Generics",
diff --git a/testsuite/tests/typecheck/should_fail/TcNoNullaryTC.hs b/testsuite/tests/typecheck/should_fail/TcNoNullaryTC.hs
new file mode 100644 (file)
index 0000000..de5e443
--- /dev/null
@@ -0,0 +1,4 @@
+module NoNullaryTC where
+
+class A where
+  f :: a -> a
diff --git a/testsuite/tests/typecheck/should_fail/TcNoNullaryTC.stderr b/testsuite/tests/typecheck/should_fail/TcNoNullaryTC.stderr
new file mode 100644 (file)
index 0000000..9619004
--- /dev/null
@@ -0,0 +1,5 @@
+
+TcNoNullaryTC.hs:3:1:
+    No parameters for class ‛A’
+    (Use -XNullaryTypeClasses to allow no-parameter classes)
+    In the class declaration for ‛A’
diff --git a/testsuite/tests/typecheck/should_fail/TcNullaryTCFail.hs b/testsuite/tests/typecheck/should_fail/TcNullaryTCFail.hs
new file mode 100644 (file)
index 0000000..b127300
--- /dev/null
@@ -0,0 +1,6 @@
+{-# LANGUAGE NullaryTypeClasses #-}
+module TcNullaryTCFail where
+
+class A
+instance A
+instance A
diff --git a/testsuite/tests/typecheck/should_fail/TcNullaryTCFail.stderr b/testsuite/tests/typecheck/should_fail/TcNullaryTCFail.stderr
new file mode 100644 (file)
index 0000000..1dd7ba2
--- /dev/null
@@ -0,0 +1,5 @@
+
+TcNullaryTCFail.hs:5:10:
+    Duplicate instance declarations:
+      instance A -- Defined at TcNullaryTCFail.hs:5:10
+      instance A -- Defined at TcNullaryTCFail.hs:6:10
index bb4d220..f1bc64f 100644 (file)
@@ -301,3 +301,5 @@ test('T7734', normal, compile_fail, [''])
 test('T7697', normal, compile_fail, [''])
 test('T7696', normal, compile_fail, [''])
 test('T7748a', normal, compile_fail, [''])
+test('TcNoNullaryTC', when(compiler_lt('ghc', '7.7'), skip), compile_fail, [''])
+test('TcNullaryTCFail', when(compiler_lt('ghc', '7.7'), skip), compile_fail, [''])
diff --git a/testsuite/tests/typecheck/should_run/TcNullaryTC.hs b/testsuite/tests/typecheck/should_run/TcNullaryTC.hs
new file mode 100644 (file)
index 0000000..a94d305
--- /dev/null
@@ -0,0 +1,13 @@
+{-# LANGUAGE NullaryTypeClasses #-}
+
+module Main where
+
+class R where
+  f :: Int -> Int
+  g :: a -> a
+
+instance R where
+  f = (+1)
+  g = id
+
+main = print (g (f 0))
diff --git a/testsuite/tests/typecheck/should_run/TcNullaryTC.stdout b/testsuite/tests/typecheck/should_run/TcNullaryTC.stdout
new file mode 100644 (file)
index 0000000..d00491f
--- /dev/null
@@ -0,0 +1 @@
+1
index 0049769..55d88ec 100755 (executable)
@@ -108,3 +108,4 @@ test('T6117', normal, compile_and_run, [''])
 test('T5751', normal, compile_and_run, [''])
 test('T5913', normal, compile_and_run, [''])
 test('T7748', normal, compile_and_run, [''])
+test('TcNullaryTC', when(compiler_lt('ghc', '7.7'), skip), compile_and_run, [''])