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

the typer checks but doesn't infer variance in the presence of type constraints #7055

Closed
vicuna opened this issue Nov 20, 2015 · 2 comments
Closed
Assignees

Comments

@vicuna
Copy link

vicuna commented Nov 20, 2015

Original bug ID: 7055
Reporter: @sliquister
Assigned to: @garrigue
Status: closed (set by @xavierleroy on 2017-02-16T14:16:27Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 4.02.3
Fixed in version: 4.03.0+dev / +beta1
Category: typing

Bug description

The following program:

module M : sig
type +'rw t constraint 'rw = [> A ] end = struct type 'rw t = unit constraint 'rw = [> A ]
end

triggers a type error:

File "/tmp/a.ml", line 3, characters 6-61:
Error: Signature mismatch:
Modules do not match:
sig type 'a t = unit constraint 'a = [> A ] end is not included in sig type +'a t constraint 'a = [> A ] end
Type declarations do not match:
type 'a t = unit constraint 'a = [> A ] is not included in type +'a t constraint 'a = [> A ]
File "/tmp/a.ml", line 2, characters 2-38: Expected declaration
File "/tmp/a.ml", line 4, characters 2-44: Actual declaration
Their variances do not agree.

Notice that the t in the structure doesn't have a variance
annotation. If I put the variance annotation on the structure too, the
code types. If I remove the constraint, the code types.

I don't know if that's a known limitation or a bug. Of course it's not
a big problem, although the error in my original program was rather
confusing. It looked like a more complicated version of this:

module M : sig
type +'rw t constraint 'rw = [> A ] type +'rw t2 = 'rw t end = struct type +'rw t = unit constraint 'rw = [> A ]
type 'rw t2 = 'rw t
end

I had the same error as above but on t2, despite t2 being obviously covariant
in 'rw in both the interface and the implementation.

@vicuna
Copy link
Author

vicuna commented Nov 21, 2015

Comment author: @garrigue

This is an intentional limitation: it is already hard to check that the variance is correct in presence of constraints (cf. injectivity problems), inferring it is not really an option.
However, I checked the manual for 4.02, and it doesn't mention that fact, so this should be added.

@vicuna
Copy link
Author

vicuna commented Nov 30, 2015

Comment author: @garrigue

Corrected the manual in commit 2934161.

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