Browse Source

changed Std.instance definition (close #2534)

Nicolas Cannasse 11 years ago
parent
commit
b84884d7d8

+ 1 - 1
std/Std.hx

@@ -38,7 +38,7 @@ extern class Std {
 		Returns null if the object is not an instance of the class.
 		Returns null if the object is not an instance of the class.
 		Is not guaranteed to work with interfaces or core types such as String, Array and Date.
 		Is not guaranteed to work with interfaces or core types such as String, Array and Date.
 	**/
 	**/
-	public static function instance<T>( v : {}, c : Class<T> ) : T;
+	public static function instance<T:{},S:T>( value : T, c : Class<S> ) : S;
 
 
 	/**
 	/**
 		Converts any value to a String.
 		Converts any value to a String.

+ 2 - 2
std/cpp/_std/Std.hx

@@ -24,8 +24,8 @@
 		return untyped __global__.__instanceof(v,t);
 		return untyped __global__.__instanceof(v,t);
 	}
 	}
 
 
-	@:keep public static function instance<T>( v : { }, c : Class<T> ) : T {
-		return Std.is(v, c) ? cast v : null;
+	@:keep public static function instance<T:{},S:T>( value : T, c : Class<S> ) : S {
+		return Std.is(value, c) ? cast value : null;
 	}
 	}
 
 
 	@:keep public static function string( s : Dynamic ) : String {
 	@:keep public static function string( s : Dynamic ) : String {

+ 2 - 2
std/cs/_std/Std.hx

@@ -234,8 +234,8 @@ import cs.internal.Exceptions;
 		}
 		}
 	}
 	}
 
 
-	public static function instance<T>( v : { }, c : Class<T> ) : T {
-		return Std.is(v, c) ? cast v : null;
+	public static function instance<T:{},S:T>( value : T, c : Class<S> ) : S {
+		return Std.is(value, c) ? cast value : null;
 	}
 	}
 
 
 	public static function random( x : Int ) : Int {
 	public static function random( x : Int ) : Int {

+ 2 - 2
std/flash/_std/Std.hx

@@ -27,8 +27,8 @@ import flash.Boot;
 		return untyped flash.Boot.__instanceof(v,t);
 		return untyped flash.Boot.__instanceof(v,t);
 	}
 	}
 
 
-	public inline static function instance<T>( v : { }, c : Class<T> ) : T {
-		return flash.Lib.as(v, c);
+	public static inline function instance<T:{},S:T>( value : T, c : Class<S> ) : S {
+		return flash.Lib.as(value, c);
 	}
 	}
 
 
 	public static function string( s : Dynamic ) : String {
 	public static function string( s : Dynamic ) : String {

+ 2 - 2
std/flash8/_std/Std.hx

@@ -26,8 +26,8 @@
 		return untyped flash.Boot.__instanceof(v,t);
 		return untyped flash.Boot.__instanceof(v,t);
 	}
 	}
 
 
-	public static function instance<T>( v : { }, c : Class<T> ) : T {
-		return Std.is(v, c) ? cast v : null;
+	public static function instance<T:{},S:T>( value : T, c : Class<S> ) : S {
+		return Std.is(value, c) ? cast value : null;
 	}
 	}
 	
 	
 	public static function string( s : Dynamic ) : String {
 	public static function string( s : Dynamic ) : String {

+ 2 - 2
std/java/_std/Std.hx

@@ -240,8 +240,8 @@ import java.internal.Exceptions;
 		return 0.0;
 		return 0.0;
 	}
 	}
 
 
-	public static function instance<T>( v : { }, c : Class<T> ) : T {
-		return Std.is(v, c) ? cast v : null;
+	public static function instance<T:{},S:T>( value : T, c : Class<S> ) : S {
+		return Std.is(value, c) ? cast value : null;
 	}
 	}
 
 
 	public static function random( x : Int ) : Int {
 	public static function random( x : Int ) : Int {

+ 1 - 1
std/js/_std/Std.hx

@@ -28,7 +28,7 @@ import js.Boot;
 		return untyped js.Boot.__instanceof(v,t);
 		return untyped js.Boot.__instanceof(v,t);
 	}
 	}
 	
 	
-	public static inline function instance<T>( v : { }, c : Class<T> ) : T {
+	public static inline function instance<T:{},S:T>( value : T, c : Class<S> ) : S {
 		return untyped __instanceof__(v, c) ? cast v : null;
 		return untyped __instanceof__(v, c) ? cast v : null;
 	}
 	}
 
 

+ 2 - 2
std/neko/_std/Std.hx

@@ -26,8 +26,8 @@
 		return untyped neko.Boot.__instanceof(v,t);
 		return untyped neko.Boot.__instanceof(v,t);
 	}
 	}
 	
 	
-	public static function instance<T>( v : { }, c : Class<T> ) : T {
-		return Std.is(v, c) ? cast v : null;
+	public static function instance<T:{},S:T>( value : T, c : Class<S> ) : S {
+		return Std.is(value, c) ? cast value : null;
 	}
 	}
 
 
 	public static function string( s : Dynamic ) : String {
 	public static function string( s : Dynamic ) : String {

+ 2 - 2
std/php/_std/Std.hx

@@ -25,8 +25,8 @@
 		return untyped untyped __call__("_hx_instanceof", v,t);
 		return untyped untyped __call__("_hx_instanceof", v,t);
 	}
 	}
 	
 	
-	public static function instance<T>( v : { }, c : Class<T> ) : T {
-		return Std.is(v, c) ? cast v : null;
+	public static function instance<T:{},S:T>( value : T, c : Class<S> ) : S {
+		return Std.is(value, c) ? cast value : null;
 	}
 	}
 
 
 	public static function string( s : Dynamic ) : String {
 	public static function string( s : Dynamic ) : String {