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
Polymorphic methods and fields on polymorphic variants #10664
Comments
Testing indicates that the bug was introduced in 4.07 (.0 or .1), and is absent from 4.06. |
The bug seems caused by incorrect row-variable information for the scrutinee type of The following patch, which simply disables the use of presence information for better pattern-matching compilation, makes the issue disappear. diff --git a/lambda/matching.ml b/lambda/matching.ml
index 07639abac8..c28a5ec7c4 100644
--- a/lambda/matching.ml
+++ b/lambda/matching.ml
@@ -1807,7 +1807,7 @@ let divide_variant ~scopes row ctx { cases = cl; args; default = def } =
in
let head = Simple.head p in
let variants = divide rem in
- if row_field lab row = Rabsent then
+ if false && row_field lab row = Rabsent then
variants
else
let tag = Btype.hash_variant lab in
@@ -2895,7 +2895,7 @@ let combine_variant loc row arg partial ctx def (tag_lambda_list, total1, _pats)
(fun (_, f) ->
match row_field_repr f with
| Rabsent
- | Reither (true, _ :: _, _, _) ->
+ | Reither (true, _ :: _, _, _) when false ->
()
| _ -> incr num_constr)
(row_fields row) (Performing only the first change suffice, but I think requiring both is important to avoid inconsistencies cropping up.) This is of course not the right fix: the row-variable presence information should be correct. |
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. |
This (rather serious) bug is still present in |
Sorry, I had completely overlooked this one. Probably @gasche 's analysis reassured me that it was in good hands... |
Fix #10664 by fixing `Ctype.copy` in `erase_either` mode
There seems to be a problem with compiling pattern-matches against the application of a polymorphic method or field to a polymorphic variant. Here is an example with a method:
This prints
B
, whereas it should printA
. Here is a similar example with a field:This also prints
B
.The problem goes away if any of the following changes are made:
id
to'ab. 'ab -> 'ab
.id
to[ `A | `B ] -> [ `A | `B ]
.(new idfunc)#id x
orf.id x
to[ `A | `B ]
before matching.In addition,
act `B
instead also printsB
.A
instead.| _ -> "C"
at the end of the match (with or without changing the type ofact
to[> `A | `B ] -> string
) changes the return value toC
.Some brief initial discussion was here.
The text was updated successfully, but these errors were encountered: