Skip to content

Commit c76df99

Browse files
cp526dc-mak
authored andcommitted
more union workarounds in welltyped.ml
1 parent 3ddc390 commit c76df99

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

lib/coreTypeChecks.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ let check_against_core_bt core_bt cn_bt =
4141
let@ () = check_object_type (OTy_integer, param_t) in
4242
check_object_type (t, t2)
4343
| OTy_struct tag, BT.Struct tag2 when Sym.equal tag tag2 -> return ()
44-
| OTy_union _tag, _ -> fail (Pp.string "unsupported: union types")
44+
| (OTy_union _tag as core_obj_ty), bt ->
45+
if !Sym.executable_spec_enabled then (
46+
match bt with
47+
| Map (_, Option MemByte) -> return ()
48+
| _ -> mismatch (BTy_object core_obj_ty) bt)
49+
else
50+
fail (Pp.string "unsupported: union types")
4551
| OTy_floating, _ -> fail (Pp.string "unsupported: floats")
4652
| core_obj_ty, bt -> mismatch (BTy_object core_obj_ty) bt
4753
in

lib/wellTyped.ml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,8 +1735,17 @@ module BaseTyping = struct
17351735
| PEapply_fun (fname, pes) ->
17361736
let@ bt, pes = check_infer_apply_fun None fname pes pe in
17371737
return (bt, PEapply_fun (fname, pes))
1738-
| PEconstrained _
1739-
| PEunion (_, _, _)
1738+
| PEconstrained _ -> todo ()
1739+
| PEunion (tag, member, pe) ->
1740+
if !Sym.executable_spec_enabled then (
1741+
(* todo: make this proper when CN actually supports unions *)
1742+
let ct = Option.get (Sctypes.of_ctype (CF.Ctype.Ctype ([], Union tag))) in
1743+
let@ () = WCT.is_ct loc ct in
1744+
let@ pe = infer_pexpr pe in
1745+
return (Memory.bt_of_sct ct, PEunion (tag, member, pe)))
1746+
else
1747+
fail
1748+
{ loc; msg = Generic !^"unsupported: union types" } [@alert "-deprecated"]
17401749
| PEmemberof (_, _, _)
17411750
| PEconv_int (_, _)
17421751
| PEconv_loaded_int (_, _)

0 commit comments

Comments
 (0)