|
@@ -2893,15 +2893,19 @@ and type_expr ctx (e,p) (with_type:with_type) =
|
|
|
| _ -> None)
|
|
|
| _ -> None
|
|
|
) in
|
|
|
+ let wrap_quoted_meta e =
|
|
|
+ mk (TMeta((Meta.QuotedField,[],e.epos),e)) e.etype e.epos
|
|
|
+ in
|
|
|
(match a with
|
|
|
| None ->
|
|
|
let rec loop (l,acc) (f,e) =
|
|
|
- let f,add = Parser.unquote_ident f in
|
|
|
+ let f,is_quoted,is_valid = Parser.unquote_ident f in
|
|
|
if PMap.mem f acc then error ("Duplicate field in object declaration : " ^ f) p;
|
|
|
let e = type_expr ctx e Value in
|
|
|
(match follow e.etype with TAbstract({a_path=[],"Void"},_) -> error "Fields of type Void are not allowed in structures" e.epos | _ -> ());
|
|
|
let cf = mk_field f e.etype e.epos in
|
|
|
- ((f,e) :: l, if add then begin
|
|
|
+ let e = if is_quoted then wrap_quoted_meta e else e in
|
|
|
+ ((f,e) :: l, if is_valid then begin
|
|
|
if f.[0] = '$' then error "Field names starting with a dollar are not allowed" p;
|
|
|
PMap.add f cf acc
|
|
|
end else acc)
|
|
@@ -2914,7 +2918,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
|
|
|
let fields = ref PMap.empty in
|
|
|
let extra_fields = ref [] in
|
|
|
let fl = List.map (fun (n, e) ->
|
|
|
- let n,add = Parser.unquote_ident n in
|
|
|
+ let n,is_quoted,is_valid = Parser.unquote_ident n in
|
|
|
if PMap.mem n !fields then error ("Duplicate field in object declaration : " ^ n) p;
|
|
|
let e = try
|
|
|
let t = (match !dynamic_parameter with Some t -> t | None -> (PMap.find n a.a_fields).cf_type) in
|
|
@@ -2922,15 +2926,16 @@ and type_expr ctx (e,p) (with_type:with_type) =
|
|
|
let e = Codegen.AbstractCast.cast_or_unify ctx t e p in
|
|
|
(try type_eq EqStrict e.etype t; e with Unify_error _ -> mk (TCast (e,None)) t e.epos)
|
|
|
with Not_found ->
|
|
|
- if add then
|
|
|
+ if is_valid then
|
|
|
extra_fields := n :: !extra_fields;
|
|
|
type_expr ctx e Value
|
|
|
in
|
|
|
- if add then begin
|
|
|
+ if is_valid then begin
|
|
|
if n.[0] = '$' then error "Field names starting with a dollar are not allowed" p;
|
|
|
let cf = mk_field n e.etype e.epos in
|
|
|
fields := PMap.add n cf !fields;
|
|
|
end;
|
|
|
+ let e = if is_quoted then wrap_quoted_meta e else e in
|
|
|
(n,e)
|
|
|
) fl in
|
|
|
let t = (TAnon { a_fields = !fields; a_status = ref Const }) in
|