Skip to content

Fix #14200 (without breaking pr7321_ok.ml) - #14202

Merged
garrigue merged 5 commits into
ocaml:trunkfrom
COCTI:fix14200
Aug 27, 2025
Merged

Fix #14200 (without breaking pr7321_ok.ml)#14202
garrigue merged 5 commits into
ocaml:trunkfrom
COCTI:fix14200

Conversation

@garrigue

Copy link
Copy Markdown
Contributor

This fixes #14200 by checking that types exported as private keep the same variance as their internal definition.

This was supposed to be as simple as switching two lines, handling such types the same way as abstract types, but this actually breaks typing-module-bugs/pr7321_ok.ml.
The problem is that the lower bound side of variance is inferred for private types, and it may not match the one obtained as the result of a functor application.
So we should only check the upper-bound side of the variance, and just accept the inferred variance for the lower-bound side.

Note: this should at least go in 5.4, so I put the change log there.
This is not a strict unsoundness, as it only allows to change the variance given by the user, not the one inferred from the definition. But this is still serious, as phantom parameters used to encode some safety property may be ignored.

@garrigue garrigue added the bug label Aug 22, 2025
Comment thread typing/includecore.ml
(* Only check the lower bound for abstract types.
For private types, the lower bound can be inferred, and
the internal one may be wrong in the result of functors. *)
imp abstr (imp p2 p1 && imp n2 n1 && imp j2 j1))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no specific need to change this line, but for an abstract type p2 and n2 are always false, so that checking j2 would be sufficient.

@stedolan stedolan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks for the quick fix!

@garrigue
garrigue merged commit 30c570f into ocaml:trunk Aug 27, 2025
23 of 24 checks passed
@garrigue

Copy link
Copy Markdown
Contributor Author

Thank you for the review.

garrigue added a commit that referenced this pull request Aug 27, 2025
@garrigue

Copy link
Copy Markdown
Contributor Author

Cherry-picked to 5.4 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bad variance check with private aliases

2 participants