瀏覽代碼

[cpp] infer TEnumParameter enum from the field because the expression might be Dynamic (closes #2988)

Simon Krajewski 11 年之前
父節點
當前提交
2ded4297c5
共有 2 個文件被更改,包括 25 次插入4 次删除
  1. 7 4
      gencpp.ml
  2. 18 0
      tests/unit/issues/Issue2988.hx

+ 7 - 4
gencpp.ml

@@ -641,7 +641,7 @@ and cpp_function_signature tfun =
    match follow tfun with
    | TFun(args,ret) -> (type_string ret) ^ "(" ^ (gen_tfun_interface_arg_list args) ^ ")"
    | _ -> "void *"
- 
+
 and cpp_function_signature_params params = match params with
    | [t] -> cpp_function_signature t
    | _ ->  assert false;
@@ -2084,8 +2084,11 @@ and gen_expression ctx retval expression =
    (* Get precidence matching haxe ? *)
    | TBinop (op,expr1,expr2) -> gen_bin_op op expr1 expr2
    | TField (expr,_) | TEnumParameter (expr,_,_) when (is_null expr) -> output "Dynamic()"
-   | TEnumParameter (expr,_,i) ->
-      let enum = match follow expr.etype with TEnum(enum,_) -> enum | _ -> assert false in
+   | TEnumParameter (expr,ef,i) ->
+      let enum = match follow ef.ef_type with
+         | TEnum(en,_) | TFun(_,TEnum(en,_)) -> en
+         | _ -> assert false
+      in
       output (  "(::" ^ (join_class_path_remap enum.e_path "::") ^ "(");
       gen_expression ctx true expr;
       output ( "))->__Param(" ^ (string_of_int i) ^ ")")
@@ -2623,7 +2626,7 @@ let gen_member_def ctx class_def is_static is_interface field =
    ;;
 
 let path_of_string path =
-   ["@verbatim"], path 
+   ["@verbatim"], path
 ;;
 
 

+ 18 - 0
tests/unit/issues/Issue2988.hx

@@ -0,0 +1,18 @@
+package unit.issues;
+
+private enum MyEnum2 {
+    MyEnumValue(p:String);
+}
+
+class Issue2988 extends Test {
+	function test() {
+        var a : Dynamic = MyEnumValue("foo");
+		var s = "";
+        if( Std.is(a, MyEnum2) ){
+            switch( a ){
+                case MyEnumValue(s1): s = s1;
+            }
+        }
+		eq("foo", s);
+	}
+}