فهرست منبع

deal with abstracts for new closure (closes #3333)

Simon Krajewski 11 سال پیش
والد
کامیت
925acc1645
2فایلهای تغییر یافته به همراه25 افزوده شده و 3 حذف شده
  1. 13 0
      tests/unit/issues/Issue3333.hx
  2. 12 3
      typer.ml

+ 13 - 0
tests/unit/issues/Issue3333.hx

@@ -0,0 +1,13 @@
+package unit.issues;
+
+private abstract MyString(String) to String {
+    public function new (url:String) this = url;
+	public inline function get() return this;
+}
+
+class Issue3333 extends Test {
+	function test() {
+        var f = MyString.new.bind("hey");
+		eq("hey", f().get());
+	}
+}

+ 12 - 3
typer.ml

@@ -2402,12 +2402,21 @@ and type_access ctx e p mode =
 				if mode = MSet then error "Cannot set constructor" p;
 				if mode = MCall then error ("Cannot call constructor like this, use 'new " ^ (s_type_path c.cl_path) ^ "()' instead") p;
 				let monos = List.map (fun _ -> mk_mono()) c.cl_params in
-				let ct, _ = get_constructor ctx c monos p in
+				let ct, cf = get_constructor ctx c monos p in
 				let args = match follow ct with TFun(args,ret) -> args | _ -> assert false in
 				let vl = List.map (fun (n,_,t) -> alloc_var n t) args in
 				let vexpr v = mk (TLocal v) v.v_type p in
-				let t = TInst(c,monos) in
-				let ec = mk (TNew(c,monos,List.map vexpr vl)) t p in
+				let el = List.map vexpr vl in
+				let ec,t = match c.cl_kind with
+					| KAbstractImpl a ->
+						let e = type_module_type ctx (TClassDecl c) None p in
+						let e = mk (TField (e,(FStatic (c,cf)))) ct p in
+						let t = TAbstract(a,monos) in
+						make_call ctx e el t p,t
+					| _ ->
+						let t = TInst(c,monos) in
+						mk (TNew(c,monos,el)) t p,t
+				in
 				AKExpr(mk (TFunction {
 					tf_args = List.map (fun v -> v,None) vl;
 					tf_type = t;