Browse Source

[flash] keep default values of string arguments
for auto-generated ctors extending externs (closes #9273)

Aleksandr Kuzmenko 5 years ago
parent
commit
a1ff1139b0

+ 4 - 1
src/codegen/swfLoader.ml

@@ -260,9 +260,12 @@ let build_class com c file =
 						| None -> None
 						| None -> None
 						| Some v ->
 						| Some v ->
 							let v = (match v with
 							let v = (match v with
-							| HVNone | HVNull | HVNamespace _ | HVString _ ->
+							| HVNone | HVNull | HVNamespace _ ->
 								is_opt := true;
 								is_opt := true;
 								None
 								None
+							| HVString s ->
+								is_opt := true;
+								Some (String (s,SDoubleQuotes))
 							| HVBool b ->
 							| HVBool b ->
 								Some (Ident (if b then "true" else "false"))
 								Some (Ident (if b then "true" else "false"))
 							| HVInt i | HVUInt i ->
 							| HVInt i | HVUInt i ->

+ 1 - 1
src/typing/typeloadFunction.ml

@@ -255,7 +255,7 @@ let add_constructor ctx c force_constructor p =
 				let null () = Some (Texpr.Builder.make_null v.v_type v.v_pos) in
 				let null () = Some (Texpr.Builder.make_null v.v_type v.v_pos) in
 				match ctx.com.platform, def with
 				match ctx.com.platform, def with
 				| _, Some _ when not ctx.com.config.pf_static -> v, null()
 				| _, Some _ when not ctx.com.config.pf_static -> v, null()
-				| Flash, Some ({eexpr = TConst (TString _)}) -> v, null()
+				| Flash, Some ({eexpr = TConst (TString _)}) when not csup.cl_extern -> v, null()
 				| Cpp, Some ({eexpr = TConst (TString _)}) -> v, def
 				| Cpp, Some ({eexpr = TConst (TString _)}) -> v, def
 				| Cpp, Some _ -> { v with v_type = ctx.t.tnull v.v_type }, null()
 				| Cpp, Some _ -> { v with v_type = ctx.t.tnull v.v_type }, null()
 				| _ -> v, def
 				| _ -> v, def

+ 8 - 0
tests/unit/native_swf/ParentCtorWithDefaultStringArgument.as

@@ -0,0 +1,8 @@
+package {
+	public class ParentCtorWithDefaultStringArgument {
+		public var strField:String;
+		public function ParentCtorWithDefaultStringArgument(str:String = "hello") {
+			strField = str;
+		}
+	}
+}

+ 11 - 0
tests/unit/src/unit/issues/Issue9273.hx

@@ -0,0 +1,11 @@
+package unit.issues;
+
+class Issue9273 extends unit.Test {
+#if flash
+	function test() {
+		eq("hello", new HaxeExtendsSwc().strField);
+	}
+#end
+}
+
+private class HaxeExtendsSwc extends ParentCtorWithDefaultStringArgument {}