Browse Source

[matcher] fix hang when checking abstract from

see #10082
Aleksandr Kuzmenko 4 năm trước cách đây
mục cha
commit
91c3f5eb86
2 tập tin đã thay đổi với 5 bổ sung4 xóa
  1. 1 0
      extra/CHANGES.txt
  2. 4 4
      src/typing/matcher.ml

+ 1 - 0
extra/CHANGES.txt

@@ -8,6 +8,7 @@
 
 	Bugfixes:
 
+	all : fixed compiler hanging on `switch` for abstracts with implicit casts involving type parameters and constraints (#10082)
 	cpp : fixed handling of `cpp.ConstCharStar` with analyzer enabled (#9733)
 
 2021-02-09 4.2.0:

+ 4 - 4
src/typing/matcher.ml

@@ -383,7 +383,7 @@ module Pattern = struct
 					| Bad_pattern s -> error s p
 				end
 			| EArrayDecl el ->
-				let rec pattern t = match follow t with
+				let rec pattern seen t = match follow t with
 					| TFun(tl,tr) when tr == fake_tuple_type ->
 						let rec loop el tl = match el,tl with
 							| e :: el,(_,_,t) :: tl ->
@@ -400,15 +400,15 @@ module Pattern = struct
 							make pctx false t2 e
 						) el in
 						PatConstructor(con_array (List.length patterns) (pos e),patterns)
-					| TAbstract(a,tl) ->
+					| TAbstract(a,tl) as t when not (List.exists (fun t' -> shallow_eq t t') seen) ->
 						begin match TyperBase.get_abstract_froms a tl with
-							| [t2] -> pattern t2
+							| [t2] -> pattern (t :: seen) t2
 							| _ -> fail()
 						end
 					| _ ->
 						fail()
 				in
-				pattern t
+				pattern [] t
 			| EObjectDecl fl ->
 				let known_fields = ref [] in
 				let collect_field cf t filter =	match filter with