Browse Source

handle CExpr equality of static fields in pattern matcher (closes #2633)

Simon Krajewski 11 years ago
parent
commit
0910294587
2 changed files with 34 additions and 1 deletions
  1. 9 1
      matcher.ml
  2. 25 0
      tests/unit/issues/Issue2633.hx

+ 9 - 1
matcher.ml

@@ -559,9 +559,17 @@ let get_pattern_locals ctx e t =
 
 (* Match compilation *)
 
+let expr_eq e1 e2 = e1 == e2 || match e1.eexpr,e2.eexpr with
+	| TConst ct1,TConst ct2 ->
+		ct1 = ct2
+	| TField(_,FStatic(c1,cf1)),TField(_,FStatic(c2,cf2)) ->
+		c1 == c2 && cf1.cf_name = cf2.cf_name
+	| _ ->
+		false
+
 let unify_con con1 con2 = match con1.c_def,con2.c_def with
 	| CExpr e1, CExpr e2 ->
-		e1 == e2
+		expr_eq e1 e2
 	| CConst c1,CConst c2 ->
 		c1 = c2
 	| CEnum(e1,ef1),CEnum(e2,ef2) ->

+ 25 - 0
tests/unit/issues/Issue2633.hx

@@ -0,0 +1,25 @@
+package unit.issues;
+import unit.Test;
+
+@:enum abstract WorldRegion {
+    static public var MiddleCenter = 1;
+}
+
+class Issue2633 extends Test {
+
+	function test() {
+       eq(1, match(0));
+       eq(1, match(1));
+       eq(2, match(2));
+       eq(2, match(3));
+	}
+	
+	function match(i) {
+		return switch [WorldRegion.MiddleCenter, i] {
+            case [WorldRegion.MiddleCenter, 1]|[WorldRegion.MiddleCenter, 0]:
+				1;
+            case _:
+                2;
+        }
+	}
+}