Browse Source

Added a typer pass between PBuildClass and PTypeField (#8456)

* added a typer pass between PBuildClass and PTypeField to handle property-accessors relations

* its 6226

* no need for delay_late in `TypeloadFields.create_property`
Aleksandr Kuzmenko 6 years ago
parent
commit
c53201dc3f

+ 1 - 0
src/context/typecore.ml

@@ -47,6 +47,7 @@ type macro_mode =
 type typer_pass =
 	| PBuildModule			(* build the module structure and setup module type parameters *)
 	| PBuildClass			(* build the class structure *)
+	| PConnectField			(* handle associated fields, which may affect each other. E.g. a property and its getter *)
 	| PTypeField			(* type the class field, allow access to types structures *)
 	| PCheckConstraint		(* perform late constraint checks with inferred types *)
 	| PForce				(* usually ensure that lazy have been evaluated *)

+ 3 - 3
src/typing/typeloadFields.ml

@@ -1252,7 +1252,7 @@ let create_property (ctx,cctx,fctx) c f (get,set,t,eo) p =
 		with Not_found ->
 			()
 	in
-	let delay_check = if c.cl_interface then delay_late ctx PBuildClass else delay ctx PTypeField in
+	let delay_check = delay ctx PConnectField in
 	let get = (match get with
 		| "null",_ -> AccNo
 		| "dynamic",_ -> AccCall
@@ -1260,7 +1260,7 @@ let create_property (ctx,cctx,fctx) c f (get,set,t,eo) p =
 		| "default",_ -> AccNormal
 		| "get",pget ->
 			let get = "get_" ^ name in
-			if fctx.is_display_field && DisplayPosition.display_position#enclosed_in pget then delay ctx PTypeField (fun () -> display_accessor get pget);
+			if fctx.is_display_field && DisplayPosition.display_position#enclosed_in pget then delay ctx PConnectField (fun () -> display_accessor get pget);
 			if not cctx.is_lib then delay_check (fun() -> check_method get t_get);
 			AccCall
 		| _,pget ->
@@ -1279,7 +1279,7 @@ let create_property (ctx,cctx,fctx) c f (get,set,t,eo) p =
 		| "default",_ -> AccNormal
 		| "set",pset ->
 			let set = "set_" ^ name in
-			if fctx.is_display_field && DisplayPosition.display_position#enclosed_in pset then delay ctx PTypeField (fun () -> display_accessor set pset);
+			if fctx.is_display_field && DisplayPosition.display_position#enclosed_in pset then delay ctx PConnectField (fun () -> display_accessor set pset);
 			if not cctx.is_lib then delay_check (fun() -> check_method set t_set);
 			AccCall
 		| _,pset ->

+ 9 - 0
tests/misc/projects/Issue6226/Main.hx

@@ -0,0 +1,9 @@
+class Main {
+	@:deprecated
+	static var b(get, never):Int;
+	static inline function get_b() return 1;
+
+	public static function main() {
+		b;
+	}
+}

+ 1 - 0
tests/misc/projects/Issue6226/compile.hxml

@@ -0,0 +1 @@
+-main Main

+ 1 - 0
tests/misc/projects/Issue6226/compile.hxml.stderr

@@ -0,0 +1 @@
+Main.hx:7: characters 3-4 : Warning : Usage of this field is deprecated