Browse Source

remove inline constructor heuristic (closes #4327) (closes #4766)

Simon Krajewski 9 years ago
parent
commit
a9472923cf

+ 15 - 0
tests/misc/projects/Issue4766/Main1.hx

@@ -0,0 +1,15 @@
+class C {
+    public function new(f) {}
+    public function f() {}
+}
+
+abstract A(C) {
+    public function new() {
+        this = new C(this.f);
+    }
+}
+
+class Main1 {
+    static function main() {
+    }
+}

+ 2 - 0
tests/misc/projects/Issue4766/compile1-fail.hxml

@@ -0,0 +1,2 @@
+-main Main1
+--interp

+ 1 - 0
tests/misc/projects/Issue4766/compile1-fail.hxml.stderr

@@ -0,0 +1 @@
+Main1.hx:8: characters 21-25 : Missing this = value

+ 18 - 0
tests/unit/src/unit/issues/Issue4327.hx

@@ -0,0 +1,18 @@
+package unit.issues;
+
+@:callable
+abstract Example(Void->String) {
+	public function new() {
+		this = fun;
+	}
+
+	function fun() {
+		return "foo";
+	}
+}
+
+class Issue4327 extends Test {
+	function test() {
+		eq("foo", new Example()());
+	}
+}

+ 0 - 10
typeload.ml

@@ -37,25 +37,15 @@ let transform_abstract_field com this_t a_t a f =
 	| FFun fu when f.cff_name = "new" && not stat ->
 		let init p = (EVars ["this",Some this_t,None],p) in
 		let cast e = (ECast(e,None)),pos e in
-		let check_type e ct = (ECheckType(e,ct)),pos e in
 		let ret p = (EReturn (Some (cast (EConst (Ident "this"),p))),p) in
 		if Meta.has Meta.MultiType a.a_meta then begin
 			if List.mem AInline f.cff_access then error "MultiType constructors cannot be inline" f.cff_pos;
 			if fu.f_expr <> None then error "MultiType constructors cannot have a body" f.cff_pos;
 		end;
-		let has_call e =
-			let rec loop e = match fst e with
-				| ECall _ -> raise Exit
-				| _ -> Ast.map_expr loop e
-			in
-			try ignore(loop e); false with Exit -> true
-		in
 		let fu = {
 			fu 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
-			| Some (EBlock [EBinop (OpAssign,(EConst (Ident "this"),_),e),_],_ | EBinop (OpAssign,(EConst (Ident "this"),_),e),_) when not (has_call e) ->
-				Some (EReturn (Some (cast (check_type e this_t))), pos e)
 			| Some (EBlock el,p) -> Some (EBlock (init p :: el @ [ret p]),p)
 			| Some e -> Some (EBlock [init p;e;ret p],p)
 			);