[MLton] Implementing warnExnMatch

Vesa Karvonen vesa.karvonen@cs.helsinki.fi
Tue, 26 Jul 2005 20:34:49 +0300


This message is in MIME format.

---MOQ11223992890e5a33681437bcbe7bdd14e0b1934a4e
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Quoting Matthew Fluet <fluet@cs.cornell.edu>:
> You don't want to use unification, because that will raise an error when 
> the types do not unify or it will force an otherwise polymorphic type to 
> be equal to an exception type. [...]

Yes. Although there is the function TypeEnv.Type.canUnify, which is "not
side-effecting".

> It is correct, but as you say, it would probably best be factored into an 
> auxilary function:

Thanks, I applied your patch (isExn) to my working files.

> > Actually, there seems to be some room for abstraction / refactoring. If
> > you look for `val isBool' in `elaborate-core.fun', you'll find out that it
> > is defined three times identically.
> 
> Fair enough, you might push it back as to PrimTycon and TypeEnv.Type as in 
> the patch above.

I haven't refactored the code in this respect.

>   warnMatch () 
>   andalso (not (Type.isExn argType) 
>            orelse warnExnMatch ())

Ok. I also prefer this behavior.

> > Should all of the contexts be subject to `warnExnMatch' [...]
> 
> I think they should apply to all of them. [...]

Ok. It is now applied in all of the contexts, but there are two
special cases. In the case of

  val p1 = e1 and ... and pN = eN

the warning is disabled only if all bindings are of exceptions. In
the case of

  fun f a1 ... aN = ...

the warning is disabled only if N=1 and a1 is an exception.

I also wrote a simple test case.

---MOQ11223992890e5a33681437bcbe7bdd14e0b1934a4e
Content-Type: text/x-patch; name="warnExnMatch.patch"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="warnExnMatch.patch"

SW5kZXg6IG1sdG9uL2FzdC9wcmltLXR5Y29ucy5mdW4KPT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQpSQ1MgZmlsZTogL2N2
c3Jvb3QvbWx0b24vbWx0b24vbWx0b24vYXN0L3ByaW0tdHljb25zLmZ1bix2CnJldHJpZXZpbmcg
cmV2aXNpb24gMS4yOQpkaWZmIC11IC1yM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ZlY3Rvci5sZW5ndGggYXJnVHlwZXMK
KyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgYW5kYWxzbyBUeXBlLmlzRXhuCisgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAoVmVjdG9yLnN1YiAoYXJnVHlwZXMs
IDApKSkKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgIG9yZWxzZSB3YXJuRXhuTWF0Y2ggKCkpfQogCQkJCSAgICAgIGluCiAJCQkJCSBDZXhwLmVu
dGVyTGVhdmUKIAkJCQkJIChlLCBwcm9maWxlQm9keSwgc291cmNlSW5mbykKQEAgLTIxMDYsNyAr
MjExMiw5IEBACiAJCQkJCSAgICAgcmVnaW9uID0gcmVnaW9uLAogCQkJCQkgICAgIHJ1bGVzID0g
cnVsZXMsCiAJCQkJCSAgICAgdGVzdCA9IENleHAudmFyIChhcmcsIGFyZ1R5cGUpLAotCQkJCQkg
ICAgIHdhcm5NYXRjaCA9IHdhcm5NYXRjaCAoKX0sCisJCQkJCSAgICAgd2Fybk1hdGNoID0gd2Fy
bk1hdGNoICgpCisgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICBhbmRhbHNvIChub3QgKFR5cGUuaXNFeG4gYXJnVHlwZSkKKyAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9y
ZWxzZSB3YXJuRXhuTWF0Y2ggKCkpfSwKIAkJCQkgcHJvZmlsZUJvZHksCiAJCQkJIGZuICgpID0+
IFNvdXJjZUluZm8uZnVuY3Rpb24ge25hbWUgPSBuZXN0LAogCQkJCQkJCSAgICAgICByZWdpb24g
PSByZWdpb259KQpAQCAtMjE5Nyw3ICsyMjA1LDExIEBACiAJCSAgICAgIChDZGVjLlZhbCB7cnZi
cyA9IHJ2YnMsCiAJCQkJIHR5dmFycyA9IGJvdW5kLAogCQkJCSB2YnMgPSB2YnMsCi0JCQkJIHdh
cm5NYXRjaCA9IHdhcm5NYXRjaCAoKX0pCisJCQkJIHdhcm5NYXRjaCA9IHdhcm5NYXRjaCAoKQor
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYW5kYWxzbyAobm90
IChWZWN0b3IuZm9yYWxsCisgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICh2YnMsCisgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICBUeXBlLmlzRXhuIG8gQ2V4cC50eSBvICNleHAp
KQorICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
b3JlbHNlIHdhcm5FeG5NYXRjaCAoKSl9KQogCQkgICBlbmQKIAkgIGVuZCkgYXJnCiAgICAgICBh
bmQgZWxhYkV4cCAoYXJnOiBBZXhwLnQgKiBOZXN0LnQgKiBzdHJpbmcgb3B0aW9uKTogQ2V4cC50
ID0KQEAgLTIyNzksNyArMjI5MSw5IEBACiAJCQkJICByZWdpb24gPSByZWdpb24sCiAJCQkJICBy
dWxlcyA9IHJ1bGVzLAogCQkJCSAgdGVzdCA9IGUsCi0JCQkJICB3YXJuTWF0Y2ggPSB3YXJuTWF0
Y2ggKCl9CisJCQkJICB3YXJuTWF0Y2ggPSB3YXJuTWF0Y2ggKCkKKyAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICBhbmRhbHNvIChub3QgKFR5cGUuaXNFeG4gYXJn
VHlwZSkKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICBvcmVsc2Ugd2FybkV4bk1hdGNoICgpKX0KIAkJICAgZ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4gZmFsc2UKIAorICAgICAgZnVuIGlzRXhuIHQgPQorICAgICAgICAgY2FzZSB0b1R5
cGUgdCBvZgorICAgICAgICAgICAgQ29uIChjLCBfKSA9PiBUeWNvbi5pc0V4biBjCisgICAgICAg
ICAgfCBfID0+IGZhbHNlCisKICAgICAgIGZ1biBpc0ludCB0ID0KIAkgY2FzZSB0b1R5cGUgdCBv
ZgogCSAgICBDb24gKGMsIF8pID0+IFR5Y29uLmlzSW50WCBjCkluZGV4OiBtbHRvbi9lbGFib3Jh
dGUvdHlwZS1lbnYuc2lnCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT0KUkNTIGZpbGU6IC9jdnNyb290L21sdG9uL21sdG9u
L21sdG9uL2VsYWJvcmF0ZS90eXBlLWVudi5zaWcsdgpyZXRyaWV2aW5nIHJldmlzaW9uIDEuMjkK
ZGlmZiAtdSAtcjEuMjkgdHlwZS1lbnYuc2lnCi0tLSBtbHRvbi9lbGFib3JhdGUvdHlwZS1lbnYu
c2lnCTIwIE1heSAyMDA1IDE2OjM0OjI3IC0wMDAwCTEuMjkKKysrIG1sdG9uL2VsYWJvcmF0ZS90
eXBlLWVudi5zaWcJMjYgSnVsIDIwMDUgMTc6MzA6MjIgLTAwMDAKQEAgLTM4LDYgKzM4LDcgQEAK
IAkJCSAgcmVwbGFjZVN5bm9ueW1zOiBib29sLAogCQkJICB2YXI6IFR5dmFyLnQgLT4gJ2F9IC0+
ICdhCiAJICAgIHZhbCBpc0NoYXJYOiB0IC0+IGJvb2wKKyAgICAgICAgICAgIHZhbCBpc0V4bjog
dCAtPiBib29sCiAJICAgIHZhbCBpc0ludDogdCAtPiBib29sCiAJICAgIHZhbCBpc1VuaXQ6IHQg
LT4gYm9vbAogCSAgICB2YWwgbGF5b3V0OiB0IC0+IExheW91dC50Cg==

---MOQ11223992890e5a33681437bcbe7bdd14e0b1934a4e
Content-Type: application/smil; name="warn-exn-match.sml"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="warn-exn-match.sml"

ZXhjZXB0aW9uIFJlYyBvZiBleG4KCigqIFRoZXNlIGdpdmUgbm8gd2FybmluZyB3aXRoIGFubm90
YXRpb24gYHdhcm5FeG5NYXRjaCBmYWxzZScuICopCmZ1biBjYXVzZSAoUmVjIGV4bikgPSBjYXVz
ZSBleG4KdmFsIHJlYyBjYXVzZSA9IGZuIFJlYyBleG4gPT4gY2F1c2UgZXhuCnZhbCBCaW5kID0g
QmluZCBhbmQgU2l6ZSA9IFNpemUKZnVuIGNhdXNlIGV4biA9IGNhc2UgZXhuIG9mIFJlYyBleG4g
PT4gZXhuCnZhbCBtYXRjaFRlc3QgPSBmbiBTaXplID0+ICgpCgooKiBUaGVzZSBnaXZlIHdhcm5p
bmdzIHdpdGggYW5ub3RhdGlvbiBgd2FybkV4bk1hdGNoIGZhbHNlJy4gKikKdmFsIFNpemUgPSBT
aXplIGFuZCBfID0gNQpmdW4gY2F1c2UgKFJlYyBleG4pIHggPSBjYXVzZSBleG4geAo=

---MOQ11223992890e5a33681437bcbe7bdd14e0b1934a4e--