فهرست منبع

[typer] abstract ctors are special snowflakes

closes #9764
Simon Krajewski 5 سال پیش
والد
کامیت
eea674bd0b
2فایلهای تغییر یافته به همراه24 افزوده شده و 1 حذف شده
  1. 2 1
      src/typing/calls.ml
  2. 22 0
      tests/unit/src/unit/issues/Issue9764.hx

+ 2 - 1
src/typing/calls.ml

@@ -221,7 +221,8 @@ let unify_field_call ctx fa el_typed el p inline =
 			cfl,Some c,false,TClass.get_map_function c tl,(fun t -> t)
 		| FHAbstract(a,tl,c) ->
 			let map = apply_params a.a_params tl in
-			expand_overloads fa.fa_field,Some c,true,map,(fun t -> map a.a_this)
+			let tmap = if fa.fa_field.cf_name = "_new" (* TODO: BAD BAD BAD BAD *) then (fun t -> t) else (fun t -> map a.a_this) in
+			expand_overloads fa.fa_field,Some c,true,map,tmap
 	in
 	let is_forced_inline = is_forced_inline co fa.fa_field in
 	let overload_kind = if has_class_field_flag fa.fa_field CfOverload then OverloadProper

+ 22 - 0
tests/unit/src/unit/issues/Issue9764.hx

@@ -0,0 +1,22 @@
+package unit.issues;
+
+private abstract Abstracted<A>(Base<A>) {
+	public inline function new(a) this = new Base(a);
+
+	public function getThis() {
+		return this;
+	}
+}
+
+private class Base<A> {
+	public var a:A;
+	public function new(a) this.a = a;
+}
+
+class Issue9764 extends unit.Test {
+	function test() {
+		var fnew = Abstracted.new;
+		var a = fnew(1);
+		eq(1, a.getThis().a);
+	}
+}