Sfoglia il codice sorgente

raise and catch a proper error while expr mapping generics (fixed issue #1508)

Simon Krajewski 12 anni fa
parent
commit
9971aefbc6
2 ha cambiato i file con 3 aggiunte e 2 eliminazioni
  1. 2 1
      codegen.ml
  2. 1 1
      type.ml

+ 2 - 1
codegen.ml

@@ -355,7 +355,8 @@ let rec build_generic ctx c p tl =
 		List.iter loop tl;
 		let build_field f =
 			let t = generic_substitute_type gctx f.cf_type in
-			{ f with cf_type = t; cf_expr = (match f.cf_expr with None -> None | Some e -> Some (generic_substitute_expr gctx e)) }
+			try { f with cf_type = t; cf_expr = (match f.cf_expr with None -> None | Some e -> Some (generic_substitute_expr gctx e)) }
+			with Unify_error l -> error (error_msg (Unify l)) f.cf_pos
 		in
 		if c.cl_init <> None || c.cl_dynamic <> None then error "This class can't be generic" p;
 		if c.cl_ordered_statics <> [] then error "A generic class can't have static fields" p;

+ 1 - 1
type.ml

@@ -1371,7 +1371,7 @@ let map_expr_type f ft fv e =
 	| TNew (_,_,el) ->
 		let et = ft e.etype in
 		(* make sure that we use the class corresponding to the replaced type *)
-		let c, pl = (match follow et with TInst (c,pl) -> (c,pl) | TAbstract({a_impl = Some c},pl) -> c,pl | _ -> assert false) in
+		let c, pl = (match follow et with TInst (c,pl) -> (c,pl) | TAbstract({a_impl = Some c},pl) -> c,pl | t -> error [has_no_field t "new"]) in
 		{ e with eexpr = TNew (c,pl,List.map f el); etype = et }
 	| TBlock el ->
 		{ e with eexpr = TBlock (List.map f el); etype = ft e.etype }