2
0
Эх сурвалжийг харах

prevent recursive constraints (fixed issue #1337)

Nicolas Cannasse 12 жил өмнө
parent
commit
6bdf606509
1 өөрчлөгдсөн 5 нэмэгдсэн , 2 устгасан
  1. 5 2
      typeload.ml

+ 5 - 2
typeload.ml

@@ -834,9 +834,12 @@ let rec type_type_params ctx path get_params p tp =
 		n, t
 	| _ ->
 		let r = exc_protect ctx (fun r ->
-			r := (fun _ -> t);
+			r := (fun _ -> error "Recursive constraint parameter is now allowed" p);
 			let ctx = { ctx with type_params = ctx.type_params @ get_params() } in
-			c.cl_kind <- KTypeParameter (List.map (load_complex_type ctx p) tp.tp_constraints);
+			let constr = List.map (load_complex_type ctx p) tp.tp_constraints in
+			List.iter (fun t -> ignore(follow t)) constr; (* force other constraints evaluation to check recursion *)
+			c.cl_kind <- KTypeParameter constr;
+			r := (fun _ -> t);
 			t
 		) "constraint" in
 		delay ctx PForce (fun () -> ignore(!r()));