Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006342OCamlOCaml typingpublic2014-03-07 07:292015-01-15 14:26
Reporterpw374 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusconfirmedResolutionopen 
PlatformOSOS Version
Product Version4.01.0 
Target Versionafter-4.02.2Fixed in Version 
Summary0006342: compiler wrongly reports "The types for field x are not equal."
DescriptionThe 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 InformationTried with 3.12.1, 4.00.1 and 4.01.0.
TagsNo tags attached.
Attached Filesdiff file icon 6342.diff [^] (2,167 bytes) 2015-01-15 14:26 [Show Content]

- Relationships

-  Notes
(0011019)
lefessan (developer)
2014-03-07 09:50

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".
(0011020)
dbuenzli (reporter)
2014-03-07 10:03

Fabrice, the *field name* mentioned is wrong in the error message, it should be "the type for field v are not equal".
(0011021)
lefessan (developer)
2014-03-07 10:14

Indeed !
(0013099)
doligez (administrator)
2015-01-15 00:52

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.

I've no idea how to fix this.
(0013107)
frisch (developer)
2015-01-15 14:25
edited on: 2015-01-15 14:26

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).


- Issue History
Date Modified Username Field Change
2014-03-07 07:29 pw374 New Issue
2014-03-07 09:50 lefessan Note Added: 0011019
2014-03-07 09:51 lefessan Assigned To => lefessan
2014-03-07 09:51 lefessan Status new => feedback
2014-03-07 10:03 dbuenzli Note Added: 0011020
2014-03-07 10:14 lefessan Note Added: 0011021
2014-07-16 18:24 doligez Target Version => 4.02.1+dev
2014-09-04 00:25 doligez Target Version 4.02.1+dev => undecided
2014-09-15 09:53 doligez Target Version undecided => 4.02.2+dev / +rc1
2015-01-15 00:38 doligez Target Version 4.02.2+dev / +rc1 => after-4.02.2
2015-01-15 00:52 doligez Note Added: 0013099
2015-01-15 00:52 doligez Assigned To lefessan =>
2015-01-15 00:52 doligez Status feedback => confirmed
2015-01-15 14:25 frisch Note Added: 0013107
2015-01-15 14:26 frisch File Added: 6342.diff
2015-01-15 14:26 frisch Note Edited: 0013107 View Revisions


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker