فهرست منبع

[cpp] Fix optional Int64 in interfaces. Closes https://github.com/HaxeFoundation/hxcpp/issues/225

hughsando 10 سال پیش
والد
کامیت
df27b1b5f4
3فایلهای تغییر یافته به همراه24 افزوده شده و 2 حذف شده
  1. 1 1
      extra/haxelib_src
  2. 4 1
      gencpp.ml
  3. 19 0
      tests/unit/src/unit/hxcpp_issues/Issue225.hx

+ 1 - 1
extra/haxelib_src

@@ -1 +1 @@
-Subproject commit 68f25d97dc991516c02a2665081ba5cc0d2ae23e
+Subproject commit 0dfb33242a28d5a89178c1e48968174646e0fefe

+ 4 - 1
gencpp.ml

@@ -760,10 +760,13 @@ and cpp_function_signature_params params = match params with
 
 and gen_interface_arg_type_name name opt typ =
    let type_str = (type_string typ) in
-   (if (opt && (cant_be_null typ) ) then
+   (* type_str may have already converted Null<X> to Dynamic because of NotNull tag ... *)
+   (if (opt && (cant_be_null typ) && type_str<>"Dynamic" ) then
       "hx::Null< " ^ type_str ^ " > "
    else
       type_str )
+
+
    ^ " " ^ (keyword_remap name)
 and gen_tfun_interface_arg_list args =
    String.concat "," (List.map (fun (name,opt,typ) -> gen_interface_arg_type_name name opt typ) args)

+ 19 - 0
tests/unit/src/unit/hxcpp_issues/Issue225.hx

@@ -0,0 +1,19 @@
+package unit.hxcpp_issues;
+
+import haxe.Int64;
+using haxe.Int64;
+
+interface InterfaceWithDefaultI64 {
+   public function optionalI64(?i:Int64) : Int;
+}
+
+class Issue225 extends Test implements InterfaceWithDefaultI64 {
+	function test() {
+      var i:InterfaceWithDefaultI64 = new Issue225();
+      eq(i.optionalI64(), -1);
+      eq(i.optionalI64(Int64.make(0,1)), 1);
+   }
+   public function optionalI64(?i:Int64)
+       return i==null ? -1 : i.toInt();
+}
+