Commit | Line | Data |
---|---|---|
7f918cf1 CE |
1 | (* |
2 | * This example tests for a bug that was in refFlatten at one point. The idea | |
3 | * is to allocate a ref cell outside a loop, and then allocate a tuple containing | |
4 | * the ref cell at each iteration of the loop. At one point, refFlatten | |
5 | * mistakenly flattened the ref cell, which meant that it wasn't shared across | |
6 | * all the tuples allocated in the loop, as it should have been. | |
7 | *) | |
8 | fun loop i = | |
9 | if i = 0 | |
10 | then () | |
11 | else | |
12 | let | |
13 | val r = ref 13 | |
14 | val l = List.tabulate (10, fn i => (r, ref i)) | |
15 | val (r1, r2) = List.nth (l, 0) | |
16 | val () = r1 := !r2 | |
17 | val (r1, _) = List.nth (l, 1) | |
18 | val () = print (concat [Int.toString (!r1), "\n"]) | |
19 | in | |
20 | loop (i - 1) | |
21 | end | |
22 | ||
23 | val () = loop 2 |