Check return modes in type_argument after eliminating optionals #734
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:then the expression
use mklocal
currently compiles without error, ignoring thelocal_
return mode. This patch makesuse 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-specificcaml_curry
andcaml_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.