You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 6342 Reporter: pw374 Assigned to:@alainfrisch Status: closed (set by @xavierleroy on 2017-02-16T14:16:17Z) Resolution: fixed Priority: normal Severity: minor Version: 4.01.0 Target version: 4.03.0+dev / +beta1 Fixed in version: 4.03.0+dev / +beta1 Category: typing
Bug description
The compiler gives some wrong information for 2 type declarations that don't match.
Steps to reproduce
$ cat mt.ml
module M = struct
type 'a v = {
x : int;
v : 'a;
} constraint 'a = [> X ] end $ cat mt.mli module M : sig type 'a v = { x : int; v : 'a; } end $ ocamlc -c mt.mli $ ocamlc -c mt.ml File "mt.ml", line 1: Error: The implementation mt.ml does not match the interface mt.cmi: In module M: Modules do not match: sig type 'a v = 'a M.v = { x : int; v : 'a; } constraint 'a = [> X ]
end
is not included in
sig type 'a v = { x : int; v : 'a; } end
In module M:
Type declarations do not match:
type 'a v = 'a M.v = { x : int; v : 'a; } constraint 'a = [> `X ]
is not included in
type 'a v = { x : int; v : 'a; }
File "mt.ml", line 2, characters 6-68: Actual declaration
The types for field x are not equal.
$
The last part "The types for field x are not equal." is wrong and sounds random, since 1. the error is elsewhere and 2. the types for field x are actually well equal...
For me, the two types are indeed not equal: 'a has a constraint internally, whereas the interface has no constraint. With the interface, you can create a value of type "int v", whereas the code in the implementation expects a "[> `X] v", i.e. would fail on an "int v".
The problem is in includecore.ml, function compare_records, line 194, where it compares not just the field types, but also the type parameters of the whole record.
When the type parameters are incompatible, it will always give the error on the first field, even if this field doesn't involve the incompatible parameters.
For a more striking example, you can remove field v from the sample code, and you still get the same error.
Isn't it enough to do the check "Ctype.equal env true decl1.type_params decl2.type_params" before the pattern matching on type_kind? I've uploaded a patch (which only moves code).
Original bug ID: 6342
Reporter: pw374
Assigned to: @alainfrisch
Status: closed (set by @xavierleroy on 2017-02-16T14:16:17Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 4.01.0
Target version: 4.03.0+dev / +beta1
Fixed in version: 4.03.0+dev / +beta1
Category: typing
Bug description
The compiler gives some wrong information for 2 type declarations that don't match.
Steps to reproduce
$ cat mt.ml
module M = struct
type 'a v = {
x : int;
v : 'a;
} constraint 'a = [>
X ] end $ cat mt.mli module M : sig type 'a v = { x : int; v : 'a; } end $ ocamlc -c mt.mli $ ocamlc -c mt.ml File "mt.ml", line 1: Error: The implementation mt.ml does not match the interface mt.cmi: In module M: Modules do not match: sig type 'a v = 'a M.v = { x : int; v : 'a; } constraint 'a = [>
X ]end
is not included in
sig type 'a v = { x : int; v : 'a; } end
In module M:
Type declarations do not match:
type 'a v = 'a M.v = { x : int; v : 'a; } constraint 'a = [> `X ]
is not included in
type 'a v = { x : int; v : 'a; }
File "mt.ml", line 2, characters 6-68: Actual declaration
The types for field x are not equal.
$
The last part "The types for field x are not equal." is wrong and sounds random, since 1. the error is elsewhere and 2. the types for field x are actually well equal...
Additional information
Tried with 3.12.1, 4.00.1 and 4.01.0.
File attachments
The text was updated successfully, but these errors were encountered: