Skip to content

Commit 19e1daa

Browse files
authored
Merge pull request #574 from mtzguido/anon
Add missing recursive calls when anonymizing unions
2 parents 5562d4a + c2d1682 commit 19e1daa

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/DataTypes.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,8 @@ let anonymous_unions (map, _, _) = object (self)
11781178
| [ Some f1, t1; Some f2, t2 ], TQualified lid when
11791179
f1 = field_for_tag && f2 = field_for_union &&
11801180
is_tagged_union map lid ->
1181+
(* No need to visit t1, it's a tag. *)
1182+
let t2 = self#visit_expr_w env t2 in
11811183
EFlat [ Some f1, t1; None, t2 ]
11821184
| _ ->
11831185
EFlat (self#visit_fields_e_opt_w env fields)

test/NestedAnonUnions.fst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module NestedAnonUnions
2+
3+
module HST = FStar.HyperStack.ST
4+
5+
// The code generated for A1 true used a val field even when using anonymous unions.
6+
// $ ./krml Bug.fst -skip-linking
7+
// ✘ [CC,oo/Bug.c] (use -verbose to see the output)
8+
// oo/Bug.c: In function ‘Bug_dummy’:
9+
// oo/Bug.c:45:62: error: ‘Bug_t1’ {aka ‘struct Bug_t1_s’} has no member named ‘val’
10+
// 45 | ((Bug_t2){ .tag = Bug_A2, { .case_A2 = { .tag = Bug_A1, .val = { .case_A1 = true } } } });
11+
// | ^~~
12+
13+
noeq type t1 = | A1 of bool | B1 of bool
14+
noeq type t2 = | A2 of t1 | B2 of bool
15+
16+
let dummy () : t2 =
17+
A2 (A1 true)
18+
19+
let dummy2 () : t2 =
20+
[@@CInline]
21+
let zero: t1 = A1 true in
22+
A2 zero
23+
24+
let main () : HST.St Int32.t =
25+
0l

0 commit comments

Comments
 (0)