Browse Source

use type_expr_with_type for static vars default value typing

Nicolas Cannasse 13 years ago
parent
commit
78640c4afb
3 changed files with 6 additions and 4 deletions
  1. 3 0
      typecore.ml
  2. 1 1
      typeload.ml
  3. 2 3
      typer.ml

+ 3 - 0
typecore.ml

@@ -102,6 +102,7 @@ type error_msg =
 exception Error of error_msg * pos
 exception Error of error_msg * pos
 
 
 let type_expr_ref : (typer -> Ast.expr -> bool -> texpr) ref = ref (fun _ _ _ -> assert false)
 let type_expr_ref : (typer -> Ast.expr -> bool -> texpr) ref = ref (fun _ _ _ -> assert false)
+let type_expr_with_type_ref : (typer -> Ast.expr -> t option -> bool -> texpr) ref = ref (fun _ _ _ -> assert false)
 
 
 let unify_error_msg ctx = function
 let unify_error_msg ctx = function
 	| Cannot_unify (t1,t2) ->
 	| Cannot_unify (t1,t2) ->
@@ -155,6 +156,8 @@ let error msg p = raise (Error (Custom msg,p))
 
 
 let type_expr ctx e need_val = (!type_expr_ref) ctx e need_val
 let type_expr ctx e need_val = (!type_expr_ref) ctx e need_val
 
 
+let type_expr_with_type ctx e t do_raise = (!type_expr_with_type_ref) ctx e t do_raise
+
 let unify ctx t1 t2 p =
 let unify ctx t1 t2 p =
 	try
 	try
 		Type.unify t1 t2
 		Type.unify t1 t2

+ 1 - 1
typeload.ml

@@ -45,7 +45,7 @@ let type_function_param ctx t e opt p =
 
 
 let type_static_var ctx t e p =
 let type_static_var ctx t e p =
 	ctx.curfun <- FStatic;
 	ctx.curfun <- FStatic;
-	let e = type_expr ctx e true in
+	let e = type_expr_with_type ctx e (Some t) false in
 	unify ctx e.etype t p;
 	unify ctx e.etype t p;
 	(* specific case for UInt statics *)
 	(* specific case for UInt statics *)
 	match t with
 	match t with

+ 2 - 3
typer.ml

@@ -103,7 +103,6 @@ let object_field f =
 	if String.length f >= pflen && String.sub f 0 pflen = pf then String.sub f pflen (String.length f - pflen), false else f, true
 	if String.length f >= pflen && String.sub f 0 pflen = pf then String.sub f pflen (String.length f - pflen), false else f, true
 
 
 let type_field_rec = ref (fun _ _ _ _ _ -> assert false)
 let type_field_rec = ref (fun _ _ _ _ _ -> assert false)
-let type_expr_with_type_raise_rec = ref (fun _ _ _ -> assert false)
 
 
 (* ---------------------------------------------------------------------- *)
 (* ---------------------------------------------------------------------- *)
 (* PASS 3 : type expression & check structure *)
 (* PASS 3 : type expression & check structure *)
@@ -256,7 +255,7 @@ let rec unify_call_params ctx cf el args r p inline =
 			| _ -> error acc "Invalid")
 			| _ -> error acc "Invalid")
 		| ee :: l, (name,opt,t) :: l2 ->
 		| ee :: l, (name,opt,t) :: l2 ->
 			try
 			try
-				let e = (!type_expr_with_type_raise_rec) ctx ee (Some t) in
+				let e = type_expr_with_type ctx ee (Some t) true in
 				unify_raise ctx e.etype t e.epos;
 				unify_raise ctx e.etype t e.epos;
 				loop ((e,false) :: acc) l l2 skip
 				loop ((e,false) :: acc) l l2 skip
 			with
 			with
@@ -2905,4 +2904,4 @@ let rec create com =
 
 
 ;;
 ;;
 type_field_rec := type_field;
 type_field_rec := type_field;
-type_expr_with_type_raise_rec := type_expr_with_type_raise;
+type_expr_with_type_ref := (fun ctx e t do_raise -> if do_raise then type_expr_with_type_raise ctx e t else type_expr_with_type ctx e t);