Browse Source

fix abstract constructor position handling

Simon Krajewski 9 years ago
parent
commit
a78827de75
2 changed files with 19 additions and 2 deletions
  1. 3 2
      src/typing/typeload.ml
  2. 16 0
      tests/display/src/cases/Abstract.hx

+ 3 - 2
src/typing/typeload.ml

@@ -48,16 +48,17 @@ let transform_abstract_field com this_t a_t a f =
 		end else
 		end else
 			meta
 			meta
 		in
 		in
+		(* We don't want the generated expression positions to shadow the real code. *)
+		let p = { p with pmax = p.pmin } in
 		let fu = {
 		let fu = {
 			fu with
 			fu with
 			f_expr = (match fu.f_expr with
 			f_expr = (match fu.f_expr with
 			| None -> if Meta.has Meta.MultiType a.a_meta then Some (EConst (Ident "null"),p) else None
 			| None -> if Meta.has Meta.MultiType a.a_meta then Some (EConst (Ident "null"),p) else None
-			| Some (EBlock el,p) -> Some (EBlock (init p :: el @ [ret p]),p)
+			| Some (EBlock el,_) -> Some (EBlock (init p :: el @ [ret p]),p)
 			| Some e -> Some (EBlock [init p;e;ret p],p)
 			| Some e -> Some (EBlock [init p;e;ret p],p)
 			);
 			);
 			f_type = Some a_t;
 			f_type = Some a_t;
 		} in
 		} in
-
 		{ f with cff_name = "_new",pos f.cff_name; cff_access = AStatic :: f.cff_access; cff_kind = FFun fu; cff_meta = meta }
 		{ f with cff_name = "_new",pos f.cff_name; cff_access = AStatic :: f.cff_access; cff_kind = FFun fu; cff_meta = meta }
 	| FFun fu when not stat ->
 	| FFun fu when not stat ->
 		if Meta.has Meta.From f.cff_meta then error "@:from cast functions must be static" f.cff_pos;
 		if Meta.has Meta.From f.cff_meta then error "@:from cast functions must be static" f.cff_pos;

+ 16 - 0
tests/display/src/cases/Abstract.hx

@@ -0,0 +1,16 @@
+package cases;
+
+class Abstract extends DisplayTestCase {
+	/**
+	abstract A(Int) {
+		public function new({-3-}i{-4-}) {
+			this = i{-1-};
+			trace("f{-2-}oo");
+		}
+	}
+	**/
+	function test() {
+		eq(range(3, 4), position(pos(1)));
+		eq("String", type(pos(2)));
+	}
+}