Procházet zdrojové kódy

[cpp,hl] disable lossy implicit cast of int 64 to 32 (#10133)

* [cpp] disable lossy implicit cast of int 64 to 32

* [hl] disable lossy implicit cast of int 64 to 32

* [cpp,hl] add explicit toInt() to Int64 types

* [cpp,hl] add toInt() doc

* deprecate implicit cast of Int64 -> Int32
George Corney před 4 roky
rodič
revize
612daa7747
3 změnil soubory, kde provedl 47 přidání a 3 odebrání
  1. 15 1
      std/cpp/Int64.hx
  2. 16 1
      std/cpp/UInt64.hx
  3. 16 1
      std/hl/I64.hx

+ 15 - 1
std/cpp/Int64.hx

@@ -22,7 +22,21 @@
 
 package cpp;
 
-@:coreType @:notNull @:runtimeValue abstract Int64 from Int to Int {
+@:coreType @:notNull @:runtimeValue abstract Int64 from Int {
+
+	/**
+		Destructively cast to Int
+	**/
+	public inline function toInt():Int {
+		return cast this;
+	}
+
+	@:to
+	@:deprecated("Implicit cast from Int64 to Int (32 bits) is deprecated. Use .toInt() or explicitly cast instead.")
+	inline function implicitToInt(): Int {
+		return toInt();
+	}
+
 	@:to
 	#if !cppia inline #end function toInt64():haxe.Int64 {
 		return cast this;

+ 16 - 1
std/cpp/UInt64.hx

@@ -22,4 +22,19 @@
 
 package cpp;
 
-@:coreType @:notNull @:runtimeValue abstract UInt64 from Int to Int {}
+@:coreType @:notNull @:runtimeValue abstract UInt64 from Int {
+
+	/**
+		Destructively cast to Int
+	**/
+	public inline function toInt():Int {
+		return cast this;
+	}
+
+	@:to
+	@:deprecated("Implicit cast from UInt64 to Int (32 bits) is deprecated. Use .toInt() or explicitly cast instead.")
+	inline function implicitToInt(): Int {
+		return toInt();
+	}
+
+}

+ 16 - 1
std/hl/I64.hx

@@ -22,4 +22,19 @@
 
 package hl;
 
-@:coreType @:notNull @:runtimeValue abstract I64 to Int from Int {}
+@:coreType @:notNull @:runtimeValue abstract I64 from Int {
+
+	/**
+		Destructively cast to Int
+	**/
+	public inline function toInt():Int {
+		return cast this;
+	}
+
+	@:to
+	@:deprecated("Implicit cast from I64 to Int (32 bits) is deprecated. Use .toInt() or explicitly cast instead.")
+	inline function implicitToInt(): Int {
+		return toInt();
+	}
+
+}