Browse Source

disallow assigning to closures that are inline or have type parameters, and improve error message when trying to use inline closures as a value (closes #3385)

Simon Krajewski 11 years ago
parent
commit
56317ab8f3
1 changed files with 12 additions and 7 deletions
  1. 12 7
      typer.ml

+ 12 - 7
typer.ml

@@ -81,7 +81,7 @@ let mk_infos ctx p params =
 
 
 let check_assign ctx e =
 let check_assign ctx e =
 	match e.eexpr with
 	match e.eexpr with
-	| TLocal _ | TArray _ | TField _ ->
+	| TLocal {v_extra = None} | TArray _ | TField _ ->
 		()
 		()
 	| TConst TThis | TTypeExpr _ when ctx.untyped ->
 	| TConst TThis | TTypeExpr _ when ctx.untyped ->
 		()
 		()
@@ -1280,12 +1280,17 @@ let rec type_ident_raise ?(imported_enums=true) ctx i p mode =
 			let t = monomorphs params v.v_type in
 			let t = monomorphs params v.v_type in
 			(match e with
 			(match e with
 			| Some ({ eexpr = TFunction f } as e) ->
 			| Some ({ eexpr = TFunction f } as e) ->
-				(* create a fake class with a fake field to emulate inlining *)
-				let c = mk_class ctx.m.curmod (["local"],v.v_name) e.epos in
-				let cf = { (mk_field v.v_name v.v_type e.epos) with cf_params = params; cf_expr = Some e; cf_kind = Method MethInline } in
-				c.cl_extern <- true;
-				c.cl_fields <- PMap.add cf.cf_name cf PMap.empty;
-				AKInline (mk (TConst TNull) (TInst (c,[])) p, cf, FInstance(c,[],cf), t)
+				begin match mode with
+					| MSet -> error "Cannot set inline closure" p
+					| MGet -> error "Cannot create closure on inline closure" p
+					| MCall ->
+						(* create a fake class with a fake field to emulate inlining *)
+						let c = mk_class ctx.m.curmod (["local"],v.v_name) e.epos in
+						let cf = { (mk_field v.v_name v.v_type e.epos) with cf_params = params; cf_expr = Some e; cf_kind = Method MethInline } in
+						c.cl_extern <- true;
+						c.cl_fields <- PMap.add cf.cf_name cf PMap.empty;
+						AKInline (mk (TConst TNull) (TInst (c,[])) p, cf, FInstance(c,[],cf), t)
+				end
 			| _ ->
 			| _ ->
 				AKExpr (mk (TLocal v) t p))
 				AKExpr (mk (TLocal v) t p))
 		| _ ->
 		| _ ->