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
Incorrect variance annotation discarded #8698
Comments
This looks like a bug indeed. Thanks for the report. |
Note that one can verify that the type was indeed inferred as invariant: # let x: 'a t = `Foo (fun _ -> ());;
val x : ([> `Foo of 'a -> unit ] as 'a) t = `Foo <fun>
# (fun x -> x) x;;
- : (_[> `Foo of 'a -> unit ] as 'a) t = `Foo <fun> So there should definitely be an error message. |
Well, actually I'm no longer sure this is a bug. I admit this is a bit confusing, but this is a consequence of variance applying only to (non-instantiated) type variables. For now, I just remove the bug label. |
While this appears not to be a bug, it had me thinking a while before checking it with the debugger, and understanding what was happening. There are two things that could be done:
Some thoughts? A more radical approach would be to go further in the direction suggested by @gasche in #8701, and allow annotations on type variables rather than parameters. The trouble is that this means adding them inside the syntax of types themselves (even row variables!), and protect against those annotations being used in unrelated places. That would be a big change. |
For me the definition of covariance of |
Thanks for the analysis @garrigue! I think the same way as @gasche about variance (as a monotonicity/anti-monotonicity property of type-level functions, rather than a property of type variables). I had a go at translating your explanation into this language, but I'm not sure if it matches yours. Does the following make sense to you? In All functions whose domain is a one-point set are monotonic (and also anti-monotonic, and injective, and order-embeddings). So, when the domain is so restricted as to be only a single type, the covariance annotation is meaningless: |
After some discussion with @lpw25, I realise things are a bit more subtle: there are in fact many types of the form |
This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc. |
If I write the following incorrect type:
the typechecker accepts it, pretending that I had never written the incorrect variance annotation:
whereas it should reject my type definition.
The text was updated successfully, but these errors were encountered: