From 2476a85973ed0d32021ac662486cebd0549059b8 Mon Sep 17 00:00:00 2001
From: simonpj <unknown>
Date: Tue, 9 Feb 1999 08:53:05 +0000
Subject: [PATCH] [project @ 1999-02-09 08:53:05 by simonpj] Fix typechecker
 bug so that

	main :: a
	main = error "Urk"

gives a sensible error message rather than crashing the compiler
---
 ghc/compiler/typecheck/TcBinds.lhs | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/ghc/compiler/typecheck/TcBinds.lhs b/ghc/compiler/typecheck/TcBinds.lhs
index 6f62328f3861..49dfed223b5d 100644
--- a/ghc/compiler/typecheck/TcBinds.lhs
+++ b/ghc/compiler/typecheck/TcBinds.lhs
@@ -692,17 +692,24 @@ now (ToDo).
 \begin{code}
 checkSigMatch top_lvl binder_names mono_ids sigs
   | main_bound_here
-  = mapTc check_one_sig sigs			`thenTc_`
-    mapTc check_main_ctxt sigs			`thenTc_` 
-
-	-- Now unify the main_id with IO t, for any old t
+  =	-- First unify the main_id with IO t, for any old t
     tcSetErrCtxt mainTyCheckCtxt (
 	tcLookupTyCon ioTyCon_NAME		`thenTc`    \ ioTyCon ->
 	newTyVarTy boxedTypeKind		`thenNF_Tc` \ t_tv ->
 	unifyTauTy ((mkTyConApp ioTyCon [t_tv]))
 		   (idType main_mono_id)
     )						`thenTc_`
-    returnTc (Just ([], emptyLIE))
+
+	-- Now check the signatures
+	-- Must do this after the unification with IO t, 
+	-- in case of a silly signature like
+	-- 	main :: forall a. a
+	-- The unification to IO t will bind the type variable 'a',
+	-- which is just waht check_one_sig looks for
+    mapTc check_one_sig sigs			`thenTc_`
+    mapTc check_main_ctxt sigs			`thenTc_` 
+
+	    returnTc (Just ([], emptyLIE))
 
   | not (null sigs)
   = mapTc check_one_sig sigs			`thenTc_`
-- 
GitLab