Browse Source

complain about missing fields before complaining about extra ones (fixed issue #925)

Simon Krajewski 13 năm trước cách đây
mục cha
commit
687c9dd699
1 tập tin đã thay đổi với 3 bổ sung3 xóa
  1. 3 3
      typer.ml

+ 3 - 3
typer.ml

@@ -1517,12 +1517,12 @@ and type_expr_with_type_raise ctx e t =
 				) el in
 				) el in
  				let t = (TAnon { a_fields = !fields; a_status = ref Const }) in
  				let t = (TAnon { a_fields = !fields; a_status = ref Const }) in
 				if not ctx.untyped then begin
 				if not ctx.untyped then begin
+					PMap.iter (fun n cf ->
+							if not (has_meta ":optional" cf.cf_meta) && not (PMap.mem n !fields) then raise (Error (Unify [has_no_field t n],p));
+					) a.a_fields;
 					(match !extra_fields with
 					(match !extra_fields with
 						| [] -> ()
 						| [] -> ()
 						| _ -> raise (Error (Unify (List.map (fun n -> has_extra_field t n) !extra_fields),p)));
 						| _ -> raise (Error (Unify (List.map (fun n -> has_extra_field t n) !extra_fields),p)));
-					PMap.iter (fun n cf ->
-							if not (has_meta ":optional" cf.cf_meta) && not (PMap.mem n !fields) then raise (Error (Unify [has_no_field t n],p));
-					) a.a_fields
 				end;
 				end;
 				a.a_status := Closed;
 				a.a_status := Closed;
 				mk (TObjectDecl el) t p
 				mk (TObjectDecl el) t p