Browse Source

delayed typing of optional param default value (should prevent cycles)

Nicolas Cannasse 17 years ago
parent
commit
2a8122ecbd
1 changed files with 16 additions and 7 deletions
  1. 16 7
      typeload.ml

+ 16 - 7
typeload.ml

@@ -38,13 +38,9 @@ let type_constant ctx c p =
 let type_function_param ctx t e opt p =
 let type_function_param ctx t e opt p =
 	match e with
 	match e with
 	| None ->
 	| None ->
-		if opt then ctx.api.tnull t, Some TNull else t, None
+		if opt then ctx.api.tnull t, Some (EConst (Ident "null"),p) else t, None
 	| Some e ->
 	| Some e ->
-		let e = type_expr ctx e true in
-		unify ctx t e.etype p;
-		match e.eexpr with
-		| TConst c -> t, Some c
-		| _ -> error "Parameter default value should be constant" p
+		t, Some e
 
 
 let exc_protect f =
 let exc_protect f =
 	let rec r = ref (fun() ->
 	let rec r = ref (fun() ->
@@ -449,7 +445,20 @@ let type_type_params ctx path p (n,flags) =
 
 
 let type_function ctx args ret static constr f p =
 let type_function ctx args ret static constr f p =
 	let locals = save_locals ctx in
 	let locals = save_locals ctx in
-	let fargs = List.map (fun (n,c,t) -> add_local ctx n t, c, t) args in
+	let fargs = List.map (fun (n,c,t) -> 
+		let c = (match c with 
+			| None -> None
+			| Some e -> 
+				let p = pos e in
+				let e = type_expr ctx e true in
+				unify ctx t e.etype p;
+				match e.eexpr with
+				| TConst c -> Some c
+				| _ -> error "Parameter default value should be constant" p
+		) in
+		let n = add_local ctx n t in
+		n, c, t
+	) args in
 	let old_ret = ctx.ret in
 	let old_ret = ctx.ret in
 	let old_static = ctx.in_static in
 	let old_static = ctx.in_static in
 	let old_constr = ctx.in_constructor in
 	let old_constr = ctx.in_constructor in