Browse Source

activate `@:resolve` on abstracts (closes #3753)

Simon Krajewski 10 years ago
parent
commit
d31fa2986a
5 changed files with 21 additions and 21 deletions
  1. 1 1
      ast.ml
  2. 1 1
      common.ml
  3. 15 15
      tests/unit/src/unit/issues/Issue3753.hx
  4. 2 2
      typeload.ml
  5. 2 2
      typer.ml

+ 1 - 1
ast.ml

@@ -143,7 +143,7 @@ module Meta = struct
 		| Remove
 		| Remove
 		| Require
 		| Require
 		| RequiresAssign
 		| RequiresAssign
-		(* | Resolve *)
+		| Resolve
 		| ReplaceReflection
 		| ReplaceReflection
 		| Rtti
 		| Rtti
 		| Runtime
 		| Runtime

+ 1 - 1
common.ml

@@ -465,7 +465,7 @@ module MetaInfo = struct
 		| Remove -> ":remove",("Causes an interface to be removed from all implementing classes before generation",[UsedOn TClass])
 		| Remove -> ":remove",("Causes an interface to be removed from all implementing classes before generation",[UsedOn TClass])
 		| Require -> ":require",("Allows access to a field only if the specified compiler flag is set",[HasParam "Compiler flag to check";UsedOn TClassField])
 		| Require -> ":require",("Allows access to a field only if the specified compiler flag is set",[HasParam "Compiler flag to check";UsedOn TClassField])
 		| RequiresAssign -> ":requiresAssign",("Used internally to mark certain abstract operator overloads",[Internal])
 		| RequiresAssign -> ":requiresAssign",("Used internally to mark certain abstract operator overloads",[Internal])
-		(* | Resolve -> ":resolve",("Abstract fields marked with this metadata can be used to resolve unknown fields",[UsedOn TClassField]) *)
+		| Resolve -> ":resolve",("Abstract fields marked with this metadata can be used to resolve unknown fields",[UsedOn TClassField])
 		| ReplaceReflection -> ":replaceReflection",("Used internally to specify a function that should replace its internal __hx_functionName counterpart",[Platforms [Java;Cs]; UsedOnEither[TClass;TEnum]; Internal])
 		| ReplaceReflection -> ":replaceReflection",("Used internally to specify a function that should replace its internal __hx_functionName counterpart",[Platforms [Java;Cs]; UsedOnEither[TClass;TEnum]; Internal])
 		| Rtti -> ":rtti",("Adds runtime type informations",[UsedOn TClass])
 		| Rtti -> ":rtti",("Adds runtime type informations",[UsedOn TClass])
 		| Runtime -> ":runtime",("?",[])
 		| Runtime -> ":runtime",("?",[])

+ 15 - 15
tests/unit/src/unit/issues/Issue3753.hx

@@ -42,20 +42,20 @@ private abstract D(Map<String, String>) from Map<String, String> {
 
 
 class Issue3753 extends Test {
 class Issue3753 extends Test {
 	function test() {
 	function test() {
-		//var a:A = ["foo" => "bar", "bar" => "baz"];
-		//eq("bar", a.foo);
-		//eq("baz", a.bar);
-//
-		//var a:B = ["foo" => "bar", "bar" => "baz"];
-		//eq("bar", a.foo);
-		//eq("baz", a.bar);
-//
-		//var a:C = ["foo" => "bar", "bar" => "baz"];
-		//eq("bar", a.foo);
-		//eq("baz", a.bar);
-//
-		//var a:D = ["foo" => "bar", "bar" => "baz"];
-		//eq("bar", a.foo);
-		//eq("baz", a.bar);
+		var a:A = ["foo" => "bar", "bar" => "baz"];
+		eq("bar", a.foo);
+		eq("baz", a.bar);
+
+		var a:B = ["foo" => "bar", "bar" => "baz"];
+		eq("bar", a.foo);
+		eq("baz", a.bar);
+
+		var a:C = ["foo" => "bar", "bar" => "baz"];
+		eq("bar", a.foo);
+		eq("baz", a.bar);
+
+		var a:D = ["foo" => "bar", "bar" => "baz"];
+		eq("bar", a.foo);
+		eq("baz", a.bar);
 	}
 	}
 }
 }

+ 2 - 2
typeload.ml

@@ -2374,7 +2374,7 @@ let init_class ctx c p context_init herits fields =
 									display_error ctx ("First argument of implementation function must be " ^ (s_type (print_context()) tthis)) f.cff_pos
 									display_error ctx ("First argument of implementation function must be " ^ (s_type (print_context()) tthis)) f.cff_pos
 							end;
 							end;
 							loop ml
 							loop ml
-(* 						| (Meta.Resolve,_,_) :: _ ->
+						| (Meta.Resolve,_,_) :: _ ->
 							let targ = if Meta.has Meta.Impl f.cff_meta then tthis else ta in
 							let targ = if Meta.has Meta.Impl f.cff_meta then tthis else ta in
 							begin match follow t with
 							begin match follow t with
 								| TFun([(_,_,t1);(_,_,t2)],_) ->
 								| TFun([(_,_,t1);(_,_,t2)],_) ->
@@ -2384,7 +2384,7 @@ let init_class ctx c p context_init herits fields =
 									end
 									end
 								| _ ->
 								| _ ->
 									error ("Field type of resolve must be " ^ (s_type (print_context()) targ) ^ " -> String -> T") f.cff_pos
 									error ("Field type of resolve must be " ^ (s_type (print_context()) targ) ^ " -> String -> T") f.cff_pos
-							end *)
+							end
 						| _ :: ml ->
 						| _ :: ml ->
 							loop ml
 							loop ml
 						| [] ->
 						| [] ->

+ 2 - 2
typer.ml

@@ -1633,14 +1633,14 @@ and type_field ?(resume=false) ctx e i p mode =
 			(match ctx.curfun, e.eexpr with
 			(match ctx.curfun, e.eexpr with
 			| FunMemberAbstract, TConst (TThis) -> type_field ctx {e with etype = apply_params a.a_params pl a.a_this} i p mode;
 			| FunMemberAbstract, TConst (TThis) -> type_field ctx {e with etype = apply_params a.a_params pl a.a_this} i p mode;
 			| _ -> raise Not_found)
 			| _ -> raise Not_found)
-(* 		with Not_found -> try
+		with Not_found -> try
 			let c = (match a.a_impl with None -> raise Not_found | Some c -> c) in
 			let c = (match a.a_impl with None -> raise Not_found | Some c -> c) in
 			let cf = PMap.find "resolve" c.cl_statics in
 			let cf = PMap.find "resolve" c.cl_statics in
 			if not (Meta.has Meta.Resolve cf.cf_meta) then raise Not_found;
 			if not (Meta.has Meta.Resolve cf.cf_meta) then raise Not_found;
 			let et = type_module_type ctx (TClassDecl c) None p in
 			let et = type_module_type ctx (TClassDecl c) None p in
 			let t = apply_params a.a_params pl (field_type ctx c [] cf p) in
 			let t = apply_params a.a_params pl (field_type ctx c [] cf p) in
 			let ef = mk (TField (et,FStatic (c,cf))) t p in
 			let ef = mk (TField (et,FStatic (c,cf))) t p in
-			AKExpr ((!build_call_ref) ctx (AKUsing(ef,c,cf,e)) [EConst (String i),p] NoValue p) *)
+			AKExpr ((!build_call_ref) ctx (AKUsing(ef,c,cf,e)) [EConst (String i),p] NoValue p)
 		with Not_found ->
 		with Not_found ->
 			if !static_abstract_access_through_instance then error ("Invalid call to static function " ^ i ^ " through abstract instance") p
 			if !static_abstract_access_through_instance then error ("Invalid call to static function " ^ i ^ " through abstract instance") p
 			else no_field())
 			else no_field())