浏览代码

when mapping open TAnon types, mutate their fields instead of creating a new TAnon (see #3128)

Simon Krajewski 10 年之前
父节点
当前提交
1047ea0013
共有 1 个文件被更改,包括 22 次插入8 次删除
  1. 22 8
      type.ml

+ 22 - 8
type.ml

@@ -479,10 +479,17 @@ let map loop t =
 	| TFun (tl,r) ->
 		TFun (List.map (fun (s,o,t) -> s, o, loop t) tl,loop r)
 	| TAnon a ->
-		TAnon {
-			a_fields = PMap.map (fun f -> { f with cf_type = loop f.cf_type }) a.a_fields;
-			a_status = a.a_status;
-		}
+		let fields = PMap.map (fun f -> { f with cf_type = loop f.cf_type }) a.a_fields in
+		begin match !(a.a_status) with
+			| Opened ->
+				a.a_fields <- fields;
+				t
+			| _ ->
+	 			TAnon {
+					a_fields = fields;
+					a_status = a.a_status;
+				}
+		end
 	| TLazy f ->
 		let ft = !f() in
 		let ft2 = loop ft in
@@ -542,10 +549,17 @@ let apply_params cparams params t =
 		| TFun (tl,r) ->
 			TFun (List.map (fun (s,o,t) -> s, o, loop t) tl,loop r)
 		| TAnon a ->
-			TAnon {
-				a_fields = PMap.map (fun f -> { f with cf_type = loop f.cf_type }) a.a_fields;
-				a_status = a.a_status;
-			}
+			let fields = PMap.map (fun f -> { f with cf_type = loop f.cf_type }) a.a_fields in
+			begin match !(a.a_status) with
+				| Opened ->
+					a.a_fields <- fields;
+					t
+				| _ ->
+		 			TAnon {
+						a_fields = fields;
+						a_status = a.a_status;
+					}
+			end
 		| TLazy f ->
 			let ft = !f() in
 			let ft2 = loop ft in