Skip to content

Check return modes in type_argument after eliminating optionals #734

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

Closed
wants to merge 1 commit into from

Conversation

stedolan
Copy link
Contributor

There is a missing mode check in type_argument, in the case where it eliminates one or more optional arguments. With the following declarations in scope:

val mklocal : ?sep:string -> local_ (string -> string)
val use : (string -> string) -> unit

then the expression use mklocal currently compiles without error, ignoring the local_ return mode. This patch makes use mklocal an error, by checking that the return mode matches the expected mode.

I suspect that this has been unsound for a while, but it is difficult to make it segfault. (Since type_argument eta-expands, the obvious approach works without error). However, the bug causes the application inside type_argument's eta-expansion to have the wrong mode, which interacts badly with the mode-specific caml_curry and caml_apply functions.

The bug became much easier to trigger after ocaml-flambda/ocaml-jst#24, and showed up in real code, from which the testsuite example is extracted. I haven't managed to construct an example that segfaults before 24, but I think one probably exists.

@stedolan
Copy link
Contributor Author

Closed in favour of the better fix in #735

@stedolan stedolan closed this Jul 19, 2022
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.

2 participants