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

Unable to override a value in a module type with ocamlc. #4487

Closed
vicuna opened this Issue Jan 22, 2008 · 5 comments

Comments

Projects
None yet
2 participants
@vicuna
Copy link
Collaborator

commented Jan 22, 2008

Original bug ID: 4487
Reporter: jm
Assigned to: @garrigue
Status: closed (set by @xavierleroy on 2012-03-24T14:01:41Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 3.10+dev
Fixed in version: 3.12.1+dev
Category: ~DO NOT USE (was: OCaml general)
Duplicate of: #5164
Related to: #5037 #5061
Monitored by: "Julien Signoles"

Bug description

% ocamlc -v
The Objective Caml compiler, version 3.10.2+dev2 (2008-01-22)
Standard library directory: /usr/local/lib/ocaml

In a module where two values have the same name and type,
ocamlc does not complain if the related signature has two entries:

% cat m.ml
module M
: sig val x : int
val x : int end
= struct let x = 0
let x = 42 end;;
print_endline (string_of_int M.x)

% ocamlc -i m.ml
module M : sig val x : int end
% ocamlc -c m.ml
% ocaml m.ml
42

But if the signature is inside a module type,
ocamlc does complain:

% cat t.ml
module type T
= sig val x : int
val x : int end
module M
: T
= struct let x = 0
let x = 42 end;;
print_endline (string_of_int M.x)

% ocamlc -i t.ml
module type T = sig val x : int val x : int end
module M : T
% ocamlc -c t.ml
The implementation t.ml does not match the interface (inferred signature):
Module type declarations do not match:
module type T = sig val x : int val x : int end
does not match
module type T = sig val x : int val x : int end
Illegal permutation of structure fields
2% ocaml t.ml
42

I would have expected ocamlc to accept a redundant value in a module type,
as ocaml does. Also, note that I'm not posting this report for the sake of hair splitting, but in order to bring into awareness a real-life issue I've encountered while dealing with module type inclusions.

Thanks for considering.

Additional information

Currently I'm somehow avoiding my real-life problem with Piotr Wieczorek's sigops.patch at:
http://rainbow.mimuw.edu.pl/~pw189451/ocaml/

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

commented May 28, 2010

Comment author: @garrigue

Fixed by only keeping the last declaration in signatures.

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

commented Dec 7, 2010

Comment author: ertai

This issue is not completely resolved, the fix seems to work only on the first duplicate.

$ cat bug.ml
module M : sig
val t : bool
val f : bool
val t : int
val f : int
end = struct
let t = 42
let f = false
end

$ ocamlc -c bug.ml
File "bug.ml", line 6, characters 6-45:
Error: Signature mismatch:
Modules do not match:
sig val t : int val f : bool end
is not included in
sig val t : int val f : int end
Values do not match: val f : bool is not included in val f : int

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

commented Dec 12, 2010

Comment author: @garrigue

The problem did exist in an intermediate fix, but it is already corrected in 3.12.
Your exemple is incorrect: the signatures inferred by the compiler are correct,
and indeed they do not match, so it is correct to report an error here.

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

commented Dec 13, 2010

Comment author: ertai

Sorry I made a mistake when reducing the bug (from around ~14000 lines of code), here is the new input:

$ cat bug.ml
module type S = sig
val t : bool
val f : bool
end
module M : sig
include S
val t : int
val f : int
end = struct
let t = 0
let f = 1
end

$ ocamlc -c bug.ml
File "bug.ml", line 9, characters 6-40:
Error: Signature mismatch:
Modules do not match:
sig val t : int val f : int end
is not included in
sig val f : bool val t : int val f : int end
Values do not match: val f : int is not included in val f : bool

This is the same output in 3.12, and today's trunk version.

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

commented Dec 13, 2010

Comment author: @garrigue

Sorry for the confusion: this problem is completely fixed only in the
3.12 branch, i.e. in the upcoming version 3.12.1.
The fix will be merged in trunk following the release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.