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

compiler wrongly reports "The types for field x are not equal." #6342

Closed
vicuna opened this Issue Mar 7, 2014 · 5 comments

Comments

Projects
None yet
2 participants
@vicuna
Copy link
Collaborator

commented Mar 7, 2014

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

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

commented Mar 7, 2014

Comment author: @lefessan

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

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

commented Mar 7, 2014

Comment author: @dbuenzli

Fabrice, the field name mentioned is wrong in the error message, it should be "the type for field v are not equal".

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

commented Mar 7, 2014

Comment author: @lefessan

Indeed !

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 14, 2015

Comment author: @damiendoligez

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.

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 15, 2015

Comment author: @alainfrisch

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

@vicuna vicuna closed this Feb 16, 2017

@vicuna vicuna added the typing label Mar 14, 2019

@vicuna vicuna added this to the 4.03.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
You can’t perform that action at this time.