Browse Source

[cs] Use toDouble to guard against boxed int -> double class cast error. Closes #2304

Cauê Waneck 11 years ago
parent
commit
64c0bd519a
2 changed files with 15 additions and 4 deletions
  1. 2 2
      std/cs/internal/Runtime.hx
  2. 13 2
      tests/unit/issues/Issue2304.hx

+ 2 - 2
std/cs/internal/Runtime.hx

@@ -681,7 +681,7 @@ import cs.system.Type;
 		if (hxObj != null)
 			return hxObj.__hx_getField_f(field, (fieldHash == 0) ? haxe.lang.FieldLookup.hash(field) : fieldHash, throwErrors, false);
 
-		return (double)slowGetField(obj, field, throwErrors);
+		return toDouble(slowGetField(obj, field, throwErrors));
 
 	')
 	public static function getField_f(obj:Dynamic, field:String, fieldHash:Int, throwErrors:Bool):Float
@@ -709,7 +709,7 @@ import cs.system.Type;
 		if (hxObj != null)
 			return hxObj.__hx_setField_f(field, (fieldHash == 0) ? haxe.lang.FieldLookup.hash(field) : fieldHash, value, false);
 
-		return (double)slowSetField(obj, field, value);
+		return toDouble(slowSetField(obj, field, value));
 
 	')
 	public static function setField_f(obj:Dynamic, field:String, fieldHash:Int, value:Float):Float

+ 13 - 2
tests/unit/issues/Issue2304.hx

@@ -13,9 +13,20 @@ private interface ITest
 {
 	var field(default,null):Int;
 }
-private class TestImpl implements ITest
+
+private class TestImpl extends BaseTest implements ITest
+{
+	public var field(default,null):Int;
+	public function new()
+	{
+		super();
+		field = 5;
+	}
+}
+
+@:nativeGen
+private class BaseTest
 {
-	public var field(default,null):Int = 5;
 	public function new()
 	{