summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorGabriel Scherer <gabriel.scherer@gmail.com>2019-03-01 16:07:32 +0100
committerGabriel Scherer <gabriel.scherer@gmail.com>2019-03-01 16:19:59 +0100
commit8d7d7580b3b052cbffd19ae1d0b0232e8fa0a789 (patch)
treeed396ca9f49c721da5f9c862ee1bf1cc0dcb2c90 /testsuite
parent0ffbe2d78d758dec2b377e88cb2f255fb6c36e0d (diff)
downloadocaml-8d7d7580b3b052cbffd19ae1d0b0232e8fa0a789.tar.gz
Merge pull request #2244 from gasche/mutual-rec-fix
value letrec: fix a bug in analysis of inner mutually-recursive bindings (cherry picked from commit f785be31bdeb8741bb2bc64554cfdf72e3c2c45d)
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/tests/letrec-check/basic.ml35
1 files changed, 35 insertions, 0 deletions
diff --git a/testsuite/tests/letrec-check/basic.ml b/testsuite/tests/letrec-check/basic.ml
index 6c490cf9e6..fea13c4841 100644
--- a/testsuite/tests/letrec-check/basic.ml
+++ b/testsuite/tests/letrec-check/basic.ml
@@ -326,3 +326,38 @@ Line 2, characters 2-85:
4 | | exception Not_found -> "z"
Error: This kind of expression is not allowed as right-hand side of `let rec'
|}];;
+
+
+(* To compute the dependencies of mutually-recursive bindings,
+ transitive dependencies must be taken into account.
+
+ The example below was causing a segfault in 4.08+dev.
+*)
+let rec wrong =
+ (* x depends on y,
+ and y depends on wrong,
+ so it is important to notice that x transitively depends on wrong;
+
+ an earlier version of our letrec analysis would only report that
+ y depends on wrong, which seems safe as y is not used in the
+ body.
+ *)
+ let rec x = ref y
+ and y = ref wrong
+ in ref ("foo" ^ ! ! !x);;
+[%%expect{|
+Line 10, characters 2-65:
+10 | ..let rec x = ref y
+11 | and y = ref wrong
+12 | in ref ("foo" ^ ! ! !x)..
+Error: This kind of expression is not allowed as right-hand side of `let rec'
+|}]
+
+(* in this case, x does not depend on y, so everything is fine *)
+let rec okay =
+ let rec x = ref "bar"
+ and _y = ref okay in
+ ref ("foo" ^ ! x);;
+[%%expect{|
+val okay : string ref = {contents = "foobar"}
+|}]