Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple exceptions in signatures gives an error #5815

Closed
vicuna opened this issue Nov 7, 2012 · 5 comments
Closed

Multiple exceptions in signatures gives an error #5815

vicuna opened this issue Nov 7, 2012 · 5 comments
Assignees
Milestone

Comments

@vicuna
Copy link

vicuna commented Nov 7, 2012

Original bug ID: 5815
Reporter: @lpw25
Assigned to: @garrigue
Status: closed (set by @xavierleroy on 2015-12-11T18:21:00Z)
Resolution: fixed
Priority: normal
Severity: minor
Target version: 4.01.0+dev
Fixed in version: 4.01.0+dev
Category: typing
Monitored by: @hcarty

Bug description

Multiple exceptions with the same name in a signature causes an error:

module type S = sig exception Foo exception Foo end;;

Characters -1--1:
module type S = sig exception Foo exception Foo end;;

Error: Module type declarations do not match:
module type S = sig exception Foo exception Foo end
does not match
module type S = sig exception Foo exception Foo end
At position module type S =
Illegal permutation of structure fields

This is not consistent with the behaviour of structures:

module M = struct exception Foo exception Foo end;;

module M : sig exception Foo end

The attached patch fixes this, so that multiple exceptions with the same name behave just like multiple values with the same name:

module type S = sig exception Foo exception Foo end;;

module type S = sig exception Foo end

File attachments

@vicuna
Copy link
Author

vicuna commented Jan 4, 2013

Comment author: @damiendoligez

I would rather align everything on the behaviour of types:

module type S = sig type t = A type t = A end;;

Error: Multiple definition of the type name t.
Names must be unique in a given structure or signature.

But I don't know what reasoning led to accepting multiple values in the first place.

At the very least, the error message should be fixed.

@vicuna
Copy link
Author

vicuna commented Jan 9, 2013

Comment author: @lpw25

I suggested aligning the behaviour of exceptions with the behaviour of values within signatures because their behaviours are aligned within structures.

I imagine multiple values are allowed in signatures because multiple values are allowed in structures.
This makes automated generation of signatures from structures easier.

@vicuna
Copy link
Author

vicuna commented Jun 7, 2013

Comment author: @xavierleroy

The error message is weird indeed. Note that 3.12 accepts this signature without errors, but (probably) no structure matches it. So, this is a fairly recent change.

@vicuna
Copy link
Author

vicuna commented Jun 17, 2013

Comment author: @garrigue

Actually not only this signature was accepted in 3.12, but it also matched the module
struct exception Foo end
On the other hand,
sig exception Foo of int exception Foo of bool end
doesn't match any module.
But there seems to be no good reason for such a restriction only on signatures,
whereas structures are accepted.

@vicuna
Copy link
Author

vicuna commented Jun 17, 2013

Comment author: @garrigue

Applied the patch in 4.01 and trunk, revisions 13788 and 13789.

I'm aware that having two exceptions with the same name in the same module is a very bad idea, but that problem is not about signatures.

@vicuna vicuna closed this as completed Dec 11, 2015
@vicuna vicuna added the typing label Mar 14, 2019
@vicuna vicuna added this to the 4.01.0 milestone Mar 14, 2019
@vicuna vicuna added the bug label Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants