Browse Source

fixed super cosntructor call when extending externs
(closes #9501)

Aleksandr Kuzmenko 5 years ago
parent
commit
6f4c2f33b3

+ 14 - 2
src/typing/typeloadFunction.ml

@@ -229,8 +229,20 @@ let type_function ctx args ret fmode f do_display p =
 	Std.finally save (type_function ctx args ret fmode f do_display) p
 
 let add_constructor ctx c force_constructor p =
-	match c.cl_constructor, c.cl_super with
-	| None, Some ({ cl_constructor = Some cfsup } as csup,cparams) when not c.cl_extern ->
+	let super() =
+		match c.cl_super with
+		| None -> None
+		| Some ({ cl_constructor = Some cfsup } as csup,cparams) ->
+			Some(cfsup,csup,cparams)
+		| Some (csup,cparams) ->
+			try
+				let _,cfsup = Type.get_constructor (fun ctor -> apply_params csup.cl_params cparams ctor.cf_type) csup in
+				Some(cfsup,csup,cparams)
+			with Not_found ->
+				None
+	in
+	match c.cl_constructor, super() with
+	| None, Some(cfsup,csup,cparams) when not c.cl_extern ->
 		let cf = {
 			cfsup with
 			cf_pos = p;

+ 10 - 0
tests/misc/projects/Issue9501/Externs.hx

@@ -0,0 +1,10 @@
+@:expose @:keep
+class BaseExtern {
+	public var field:Int;
+	public function new(i:Int) {
+		field = i;
+	}
+}
+
+@:expose
+class ExtendedExtern extends BaseExtern {}

+ 20 - 0
tests/misc/projects/Issue9501/Main.hx

@@ -0,0 +1,20 @@
+import haxe.Exception;
+
+extern class BaseExtern {
+	var field:Int;
+	function new(i:Int):Void;
+}
+
+@:jsRequire('./externs.js', 'ExtendedExtern')
+extern class ExtendedExtern extends BaseExtern {}
+
+class HaxeClass extends ExtendedExtern {}
+
+class Main {
+	static function main() {
+		var hx = new HaxeClass(999);
+		if(hx.field != 999) {
+			throw new Exception('Super constructor was not invoked');
+		}
+	}
+}

+ 9 - 0
tests/misc/projects/Issue9501/compile.hxml

@@ -0,0 +1,9 @@
+Externs
+-js bin/externs.js
+
+--next
+
+-main Main
+-js bin/test.js
+
+--cmd node bin/test.js