Browse Source

remove structural class extension (closes #5633) (#5641)

Dan Korostelev 9 years ago
parent
commit
05b62d63cf
5 changed files with 4 additions and 32 deletions
  1. 1 1
      src/generators/genas3.ml
  2. 0 9
      src/generators/genswf9.ml
  3. 1 1
      src/macro/interp.ml
  4. 0 3
      src/typing/type.ml
  5. 2 18
      src/typing/typeload.ml

+ 1 - 1
src/generators/genas3.ml

@@ -281,7 +281,7 @@ let rec type_str ctx t p =
 	| TInst (c,_) ->
 		(match c.cl_kind with
 		| KNormal | KGeneric | KGenericInstance _ | KAbstractImpl _ -> s_path ctx false c.cl_path p
-		| KTypeParameter _ | KExtension _ | KExpr _ | KMacroType | KGenericBuild _ -> "*")
+		| KTypeParameter _ | KExpr _ | KMacroType | KGenericBuild _ -> "*")
 	| TFun _ ->
 		"Function"
 	| TMono r ->

+ 0 - 9
src/generators/genswf9.ml

@@ -225,8 +225,6 @@ let rec type_id ctx t =
 			(match l with
 			| [t] -> type_id ctx t
 			| _ -> type_path ctx ([],"Object"))
-		| KExtension (c,params) ->
-			type_id ctx (TInst (c,params))
 		| _ ->
 			type_path ctx c.cl_path)
 	| TAbstract (a,_) ->
@@ -346,13 +344,6 @@ let property ctx p t =
 			| "ffloor" | "fceil" | "fround" -> ident (String.sub p 1 (String.length p - 1)), None, false
 			| _ -> ident p, None, false)
 		| _ -> ident p, None, false)
-	| TInst ({ cl_kind = KExtension _ } as c,params) ->
-		(* cast type when accessing an extension field *)
-		(try
-			let f = PMap.find p c.cl_fields in
-			ident p, Some (classify ctx (apply_params c.cl_params params f.cf_type)), false
-		with Not_found ->
-			ident p, None, false)
 	| TInst ({ cl_interface = true } as c,_) ->
 		(* lookup the interface in which the field was actually declared *)
 		let rec loop c =

+ 1 - 1
src/macro/interp.ml

@@ -4579,7 +4579,7 @@ and encode_class_kind k =
 	let tag, pl = (match k with
 		| KNormal -> 0, []
 		| KTypeParameter pl -> 1, [encode_tparams pl]
-		| KExtension (cl, params) -> 2, [encode_clref cl; encode_tparams params]
+		(* KExtension was here *)
 		| KExpr e -> 3, [encode_expr e]
 		| KGeneric -> 4, []
 		| KGenericInstance (cl, params) -> 5, [encode_clref cl; encode_tparams params]

+ 0 - 3
src/typing/type.ml

@@ -161,7 +161,6 @@ and tclass_field = {
 and tclass_kind =
 	| KNormal
 	| KTypeParameter of t list
-	| KExtension of tclass * tparams
 	| KExpr of Ast.expr
 	| KGeneric
 	| KGenericInstance of tclass * tparams
@@ -1223,8 +1222,6 @@ let s_class_kind = function
 		"KNormal"
 	| KTypeParameter tl ->
 		Printf.sprintf "KTypeParameter [%s]" (s_types tl)
-	| KExtension(c,tl) ->
-		Printf.sprintf "KExtension %s<%s>" (s_type_path c.cl_path) (s_types tl)
 	| KExpr _ ->
 		"KExpr"
 	| KGeneric ->

+ 2 - 18
src/typing/typeload.ml

@@ -550,28 +550,12 @@ and load_complex_type ctx allow_display p (t,pn) =
 				match follow t with
 				| TInst ({cl_kind = KTypeParameter _},_) ->
 					error "Cannot structurally extend type parameters" p
-				| TInst (c,tl) ->
-					ctx.com.warning "Structurally extending classes is deprecated and will be removed" p;
-					let c2 = mk_class null_module (fst c.cl_path,"+" ^ snd c.cl_path) p null_pos in
-					c2.cl_private <- true;
-					PMap.iter (fun f _ ->
-						try
-							ignore(class_field c tl f);
-							error ("Cannot redefine field " ^ f) p
-						with
-							Not_found -> ()
-					) a.a_fields;
-					(* do NOT tag as extern - for protect *)
-					c2.cl_kind <- KExtension (c,tl);
-					c2.cl_super <- Some (c,tl);
-					c2.cl_fields <- a.a_fields;
-					TInst (c2,[])
 				| TMono _ ->
 					error "Loop found in cascading signatures definitions. Please change order/import" p
 				| TAnon a2 ->
 					PMap.iter (fun _ cf -> ignore(is_redefined cf a2)) a.a_fields;
 					TAnon { a_fields = (PMap.foldi PMap.add a.a_fields a2.a_fields); a_status = ref (Extend [t]); }
-				| _ -> error "Can only extend classes and structures" p
+				| _ -> error "Can only extend structures" p
 			in
 			let loop t = match follow t with
 				| TAnon a2 ->
@@ -580,7 +564,7 @@ and load_complex_type ctx allow_display p (t,pn) =
 							a.a_fields <- PMap.add f cf a.a_fields
 					) a2.a_fields
 				| _ ->
-					error "Multiple structural extension is only allowed for structures" p
+					error "Can only extend structures" p
 			in
 			let il = List.map (fun (t,_) -> load_instance ctx ~allow_display (t,pn) false p) tl in
 			let tr = ref None in