Browse Source

[analyzer] do not set sub-block syntax edges to unreachable blocks (closes #4917)

Simon Krajewski 9 years ago
parent
commit
9497255c23
2 changed files with 36 additions and 5 deletions
  1. 11 5
      analyzer.ml
  2. 25 0
      tests/unit/src/unit/issues/Issue4917.hx

+ 11 - 5
analyzer.ml

@@ -1237,11 +1237,17 @@ module TexprTransformer = struct
 				close_node g bb;
 				let bb_sub_next = block_el bb_sub el in
 				scope();
-				let bb_next = create_node BKNormal bb_sub_next bb.bb_type bb.bb_pos in
-				set_syntax_edge g bb (SESubBlock(bb_sub,bb_next));
-				add_cfg_edge g bb_sub_next bb_next CFGGoto;
-				close_node g bb_sub_next;
-				bb_next;
+				if bb_sub_next != g.g_unreachable then begin
+					let bb_next = create_node BKNormal bb_sub_next bb.bb_type bb.bb_pos in
+					set_syntax_edge g bb (SESubBlock(bb_sub,bb_next));
+					add_cfg_edge g bb_sub_next bb_next CFGGoto;
+					close_node g bb_sub_next;
+					bb_next;
+				end else begin
+					set_syntax_edge g bb (SEMerge bb_sub);
+					close_node g bb_sub_next;
+					bb_sub_next
+				end
 			| TIf(e1,e2,None) ->
 				let bb,e1 = bind_to_temp bb false e1 in
 				let scope = increase_scope() in

+ 25 - 0
tests/unit/src/unit/issues/Issue4917.hx

@@ -0,0 +1,25 @@
+package unit.issues;
+
+class Issue4917 extends Test {
+	static function throwing(expected:Dynamic):Bool {
+		switch(Type.typeof(expected)) {
+			case TClass(c):
+				Std.string(expected);
+				return true;
+			case TEnum(e) :
+				Std.string(expected);
+				return true;
+			case _ :
+				throw "Unable to compare two unknown types";
+		}
+		throw "Unable to compare values: " + expected;
+	}
+
+	function test() {
+		t(throwing(new C()));
+	}
+}
+
+private class C {
+	public function new() { }
+}