Browse Source

fix `@:fakeEnum` matching again, add a test this time (closes #5184)

Simon Krajewski 9 years ago
parent
commit
b74effa3cc
2 changed files with 56 additions and 8 deletions
  1. 19 8
      src/typing/matcher.ml
  2. 37 0
      tests/unit/src/unit/issues/Issue5184.hx

+ 19 - 8
src/typing/matcher.ml

@@ -103,8 +103,11 @@ module Constructor = struct
 	open Typecore
 
 	let to_texpr ctx match_debug p con = match con with
-		| ConEnum(_,ef) ->
-			if match_debug then mk (TConst (TString ef.ef_name)) ctx.t.tstring p
+		| ConEnum(en,ef) ->
+			if Meta.has Meta.FakeEnum en.e_meta then begin
+				let e_mt = !type_module_type_ref ctx (TEnumDecl en) None p in
+ 				mk (TField(e_mt,FEnum(en,ef))) ef.ef_type p
+ 			end else if match_debug then mk (TConst (TString ef.ef_name)) ctx.t.tstring p
 			else mk (TConst (TInt (Int32.of_int ef.ef_index))) ctx.t.tint p
 		| ConConst ct -> Codegen.ExprBuilder.make_const_texpr ctx.com ct p
 		| ConArray i -> Codegen.ExprBuilder.make_int ctx.com i p
@@ -1075,6 +1078,7 @@ module TexprConverter = struct
 	type match_kind =
 		| SKValue
 		| SKEnum
+		| SKFakeEnum
 		| SKLength
 
 	exception Not_exhaustive
@@ -1095,6 +1099,7 @@ module TexprConverter = struct
 	let s_match_kind = function
 		| SKValue -> "value"
 		| SKEnum -> "enum"
+		| SKFakeEnum -> "fakeEnum"
 		| SKLength -> "length"
 
 	let unify_constructor ctx params t con =
@@ -1178,7 +1183,10 @@ module TexprConverter = struct
 				SKLength,Infinite
 			| TEnum(en,pl) ->
 				PMap.iter (fun _ ef -> add (ConEnum(en,ef))) en.e_constrs;
-				SKEnum,RunTimeFinite
+				if Meta.has Meta.FakeEnum en.e_meta then
+					SKFakeEnum,CompileTimeFinite
+				else
+					SKEnum,RunTimeFinite
 			| TAnon _ ->
 				SKValue,CompileTimeFinite
 			| TInst(_,_) ->
@@ -1187,10 +1195,13 @@ module TexprConverter = struct
 				SKValue,Infinite
 		in
 		let kind,finiteness = loop t in
-		let compatible_kind con = match con with
-			| ConEnum _ -> kind = SKEnum
-			| ConArray _ -> kind = SKLength
-			| _ -> kind = SKValue
+		let compatible_kind con = match con,kind with
+			| (ConEnum _,(SKEnum | SKFakeEnum))
+			| (ConArray _,SKLength)
+			| (_,SKValue) ->
+				true
+			| _ ->
+				false
 		in
 		List.iter (fun (con,unguarded,dt) ->
 			if not (compatible_kind con) then error "Incompatible pattern" dt.dt_pos;
@@ -1292,7 +1303,7 @@ module TexprConverter = struct
 					end
 				) cases in
 				let e_subject = match kind with
-					| SKValue -> e_subject
+					| SKValue | SKFakeEnum -> e_subject
 					| SKEnum -> if match_debug then mk_name_call e_subject else mk_index_call e_subject
 					| SKLength -> type_field_access ctx e_subject "length"
 				in

+ 37 - 0
tests/unit/src/unit/issues/Issue5184.hx

@@ -0,0 +1,37 @@
+package unit.issues;
+
+#if !flash
+
+class Issue5184 extends unit.Test { }
+
+#else
+
+import flash.display.StageQuality;
+
+class Issue5184 extends unit.Test {
+	function test() {
+		eq(0, getQ(BEST));
+		eq(1, getQ(HIGH));
+		eq(2, getQ(HIGH_16X16));
+		eq(3, getQ(HIGH_16X16_LINEAR));
+		eq(4, getQ(HIGH_8X8));
+		eq(5, getQ(HIGH_8X8_LINEAR));
+		eq(6, getQ(LOW));
+		eq(7, getQ(MEDIUM));
+	}
+
+	function getQ(q:flash.display.StageQuality) {
+		return switch (q) {
+			case BEST: 0;
+			case HIGH: 1;
+			case HIGH_16X16: 2;
+			case HIGH_16X16_LINEAR: 3;
+			case HIGH_8X8: 4;
+			case HIGH_8X8_LINEAR: 5;
+			case LOW: 6;
+			case MEDIUM: 7;
+		}
+	}
+}
+
+#end