Jelajahi Sumber

tanon identification / tunification: stricterer EqStricter

Rudy Ges 1 tahun lalu
induk
melakukan
8c7cce6be8
2 mengubah file dengan 9 tambahan dan 9 penghapusan
  1. 6 6
      src/core/tUnification.ml
  2. 3 3
      src/typing/tanon_identification.ml

+ 6 - 6
src/core/tUnification.ml

@@ -516,11 +516,11 @@ let rec type_eq uctx a b =
 	| _ , TLazy f -> type_eq uctx a (lazy_type f)
 	| TMono t , _ ->
 		(match t.tm_type with
-		| None -> if param = EqCoreType || not (link t a b) then error [cannot_unify a b]
+		| None -> if param = EqCoreType || param = EqStricter || not (link t a b) then error [cannot_unify a b]
 		| Some t -> type_eq uctx t b)
 	| _ , TMono t ->
 		(match t.tm_type with
-		| None -> if param = EqCoreType || not (link t b a) then error [cannot_unify a b]
+		| None -> if param = EqCoreType || param = EqStricter || not (link t b a) then error [cannot_unify a b]
 		| Some t -> type_eq uctx a t)
 	| TDynamic None, TDynamic None ->
 		()
@@ -630,7 +630,7 @@ let type_iseq uctx a b =
 
 let type_iseq_strict a b =
 	try
-		type_eq {default_unification_context with equality_kind = EqDoNotFollowNull} a b;
+		type_eq {default_unification_context with equality_kind = EqStricter} a b;
 		true
 	with Unify_error _ ->
 		false
@@ -660,11 +660,11 @@ let rec unify (uctx : unification_context) a b =
 	| _ , TLazy f -> unify uctx a (lazy_type f)
 	| TMono t , _ ->
 		(match t.tm_type with
-		| None -> if not (link t a b) then error [cannot_unify a b]
+		| None -> if uctx.equality_kind = EqStricter || not (link t a b) then error [cannot_unify a b]
 		| Some t -> unify uctx t b)
 	| _ , TMono t ->
 		(match t.tm_type with
-		| None -> if not (link t b a) then error [cannot_unify a b]
+		| None -> if uctx.equality_kind = EqStricter || not (link t b a) then error [cannot_unify a b]
 		| Some t -> unify uctx a t)
 	| TType (t,tl) , _ ->
 		rec_stack unify_stack (a,b)
@@ -885,7 +885,7 @@ let rec unify (uctx : unification_context) a b =
 			error [cannot_unify a b]
 		end
 	| _ , TDynamic None ->
-		()
+		if uctx.equality_kind = EqStricter then error [cannot_unify a b]
 	| _ , TDynamic (Some t1) ->
 		begin match a with
 		| TAnon an ->

+ 3 - 3
src/typing/tanon_identification.ml

@@ -1,12 +1,12 @@
 open Globals
 open Type
 
-let replace_mono t =
+let replace_mono tmono_as_tdynamic t =
 	let visited_anons = ref [] in
 	let rec loop t =
 		match t with
 		| TMono ({ tm_type = None }) ->
-			t_dynamic
+			if tmono_as_tdynamic then t_dynamic else t
 		| TAnon an ->
 			if not (List.memq an !visited_anons) then begin
 				visited_anons := an :: !visited_anons;
@@ -167,7 +167,7 @@ object(self)
 			end
 		| _ ->
 			let arity,fields = PMap.fold (fun cf (i,acc) ->
-				let t = replace_mono cf.cf_type in
+				let t = replace_mono (not strict) cf.cf_type in
 				(i + 1),(PMap.add cf.cf_name {cf with cf_type = t} acc)
 			) an.a_fields (0,PMap.empty) in
 			let an = { a_fields = fields; a_status = an.a_status; } in