Class/Implicit Param/Module Interface bug

Ashley Yakeley ashley@semantic.org
Wed, 13 Nov 2002 04:09:56 -0800


--Emailer_-1172533711
Content-Type: text/plain; charset="US-ASCII"

My program was crashing and I couldn't figure out why. Then I discovered 
this strange bug involving classes, implicit parameters, and module 
interfaces (see enclosed files). Basically the type-checker is not being 
strict enough and misses this compile-time error.

The workaround, of course, is not to make the error.


module A where
	{
	class C a where
		{
		f :: (?p :: String) => a;
		};

	instance C String where
		{
		f = ?p;
		};
	
	g :: (?p :: String) => String;
	g = ?p;
	}


{--
Compile using this:

  ghc -fglasgow-exts -c A.hs && ghc -fglasgow-exts A.o Main.hs -o bug && 
./bug

Bug won't happen with --make:

  rm bug; rm *.hi *.o; ghc -fglasgow-exts --make Main.hs -o bug && ./bug

Bug won't happen if everything is in one module.

--}
module Main where
	{
	import A;

	main = putStrLn f;	-- BUG: this compiles (and crashed when run, of 
course)
--	main = putStrLn g;	-- this correctly gives a compile-time error
	}

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 5.04
$ uname -a
Darwin Ashley-Yakeleys-Computer.local. 6.2 Darwin Kernel Version 6.2: Tue 
Nov  5 22:00:03 PST 2002; root:xnu/xnu-344.12.2.obj~1/RELEASE_PPC  Power 
Macintosh powerpc

-- 
Ashley Yakeley, Seattle WA

--Emailer_-1172533711
Content-Type: application/text; name="A.hs";
 x-mac-type="54455854";
 x-mac-creator="00000000"
Content-transfer-encoding: base64
Content-Disposition: Attachment; filename="A.hs"

bW9kdWxlIEEgd2hlcmUKCXsKCWNsYXNzIEMgYSB3aGVyZQoJCXsKCQlmIDo6ICg/cCA6OiBTdHJp
bmcpID0+IGE7CgkJfTsKCglpbnN0YW5jZSBDIFN0cmluZyB3aGVyZQoJCXsKCQlmID0gP3A7CgkJ
fTsKCQoJZyA6OiAoP3AgOjogU3RyaW5nKSA9PiBTdHJpbmc7CglnID0gP3A7Cgl9Cg==
--Emailer_-1172533711
Content-Type: application/text; name="Main.hs";
 x-mac-type="54455854";
 x-mac-creator="00000000"
Content-transfer-encoding: base64
Content-Disposition: Attachment; filename="Main.hs"

ey0tCkNvbXBpbGUgdXNpbmcgdGhpczoKCiAgZ2hjIC1mZ2xhc2dvdy1leHRzIC1jIEEuaHMgJiYg
Z2hjIC1mZ2xhc2dvdy1leHRzIEEubyBNYWluLmhzIC1vIGJ1ZyAmJiAuL2J1ZwoKQnVnIHdvbid0
IGhhcHBlbiB3aXRoIC0tbWFrZToKCiAgcm0gYnVnOyBybSAqLmhpICoubzsgZ2hjIC1mZ2xhc2dv
dy1leHRzIC0tbWFrZSBNYWluLmhzIC1vIGJ1ZyAmJiAuL2J1ZwoKQnVnIHdvbid0IGhhcHBlbiBp
ZiBldmVyeXRoaW5nIGlzIGluIG9uZSBtb2R1bGUuCgotLX0KbW9kdWxlIE1haW4gd2hlcmUKCXsK
CWltcG9ydCBBOwoKCW1haW4gPSBwdXRTdHJMbiBmOwktLSBCVUc6IHRoaXMgY29tcGlsZXMgKGFu
ZCBjcmFzaGVkIHdoZW4gcnVuLCBvZiBjb3Vyc2UpCi0tCW1haW4gPSBwdXRTdHJMbiBnOwktLSB0
aGlzIGNvcnJlY3RseSBnaXZlcyBhIGNvbXBpbGUtdGltZSBlcnJvcgoJfQo=
--Emailer_-1172533711--