Răsfoiți Sursa

do interface checks for parent classes as well (closes https://github.com/frabbit/hx2python/issues/27)

Simon Krajewski 11 ani în urmă
părinte
comite
dc78422893
2 a modificat fișierele cu 22 adăugiri și 3 ștergeri
  1. 10 3
      std/python/_std/Std.hx
  2. 12 0
      tests/unit/TestPython.hx

+ 10 - 3
std/python/_std/Std.hx

@@ -39,6 +39,7 @@ import python.Syntax;
 		}
 	}
 
+	@:access(python.Boot.getSuperClass)
 	public static function is( v : Dynamic, t : Dynamic ) : Bool {
 
 		if (v == null && t == null) {
@@ -89,6 +90,7 @@ import python.Syntax;
 		if (try Builtin.isinstance(v, t) catch (e:Dynamic) false) {
 			return true;
 		}
+
 		if (Inspect.isclass(t)) {
 
 			function loop (intf)
@@ -110,9 +112,14 @@ import python.Syntax;
 					return false;
 				}
 			}
-			return loop(Syntax.field(v, "__class__"));
-
-
+			var currentClass = Syntax.field(v, "__class__");
+			while(currentClass != null) {
+				if (loop(currentClass)) {
+					return true;
+				}
+				currentClass = python.Boot.getSuperClass(currentClass);
+			}
+			return false;
 		} else {
 			return false;
 		}

+ 12 - 0
tests/unit/TestPython.hx

@@ -15,6 +15,14 @@ private enum MyEnum {
 	False;
 }
 
+private interface IA {}
+
+private class A implements IA { }
+
+private class B extends A {
+    public function new() {}
+}
+
 class TestPython extends Test {
 
 	public function testDoWhileAsExpression () {
@@ -179,4 +187,8 @@ class TestPython extends Test {
 		eq("nullb", s2);
 		eq("nullc", s3);
     }
+
+	function testIsViaParentInterface() {
+		t(Std.is(new B(), IA));
+	}
 }