summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorschinz <schinz@epfl.ch>2005-05-19 07:02:02 +0000
committerschinz <schinz@epfl.ch>2005-05-19 07:02:02 +0000
commit507568e72cd6c0c55aba2b64645a67f731812f63 (patch)
tree05c7ae0f9d97de936a127a108bba89b9dfb0ad8c /sources
parentf53185a3333586cdc57d39dc67203d4f35949e50 (diff)
downloadscala-507568e72cd6c0c55aba2b64645a67f731812f63.tar.gz
scala-507568e72cd6c0c55aba2b64645a67f731812f63.tar.bz2
scala-507568e72cd6c0c55aba2b64645a67f731812f63.zip
- bug fix: the "cast" function now performs coe...
- bug fix: the "cast" function now performs coercion for numeric types, as it should.
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/runtime/types/TypeByte.java19
-rw-r--r--sources/scala/runtime/types/TypeChar.java19
-rw-r--r--sources/scala/runtime/types/TypeDouble.java19
-rw-r--r--sources/scala/runtime/types/TypeFloat.java19
-rw-r--r--sources/scala/runtime/types/TypeInt.java19
-rw-r--r--sources/scala/runtime/types/TypeLong.java19
-rw-r--r--sources/scala/runtime/types/TypeShort.java19
7 files changed, 112 insertions, 21 deletions
diff --git a/sources/scala/runtime/types/TypeByte.java b/sources/scala/runtime/types/TypeByte.java
index efdd977b5c..cafab096f3 100644
--- a/sources/scala/runtime/types/TypeByte.java
+++ b/sources/scala/runtime/types/TypeByte.java
@@ -19,9 +19,22 @@ public class TypeByte extends ValueType {
private final Byte ZERO = RunTime.box_bvalue((byte)0);
public Object cast(Object o) {
assert scala.runtime.types.Statistics.incTypeCast();
- if (! (o == null || o instanceof scala.Byte))
- throw new ClassCastException(); // TODO error message
- return o;
+ if (o == null || o instanceof scala.Byte)
+ return o;
+ else if (o instanceof scala.Double)
+ return RunTime.box_bvalue((byte)((scala.Double)o).value);
+ else if (o instanceof scala.Float)
+ return RunTime.box_bvalue((byte)((scala.Float)o).value);
+ else if (o instanceof scala.Long)
+ return RunTime.box_bvalue((byte)((scala.Long)o).value);
+ else if (o instanceof scala.Int)
+ return RunTime.box_bvalue((byte)((scala.Int)o).value);
+ else if (o instanceof scala.Short)
+ return RunTime.box_bvalue((byte)((scala.Short)o).value);
+ else if (o instanceof scala.Char)
+ return RunTime.box_bvalue((byte)((scala.Char)o).value);
+ else
+ throw new ClassCastException();
}
public Object defaultValue() { return ZERO; }
public boolean isSameAsJavaType(Class that) {
diff --git a/sources/scala/runtime/types/TypeChar.java b/sources/scala/runtime/types/TypeChar.java
index 970451bfcd..19d42a2887 100644
--- a/sources/scala/runtime/types/TypeChar.java
+++ b/sources/scala/runtime/types/TypeChar.java
@@ -19,9 +19,22 @@ public class TypeChar extends ValueType {
private final Char ZERO = RunTime.box_cvalue((char)0);
public Object cast(Object o) {
assert scala.runtime.types.Statistics.incTypeCast();
- if (! (o == null || o instanceof scala.Char))
- throw new ClassCastException(); // TODO error message
- return o;
+ if (o == null || o instanceof scala.Char)
+ return o;
+ else if (o instanceof scala.Double)
+ return RunTime.box_cvalue((char)((scala.Double)o).value);
+ else if (o instanceof scala.Float)
+ return RunTime.box_cvalue((char)((scala.Float)o).value);
+ else if (o instanceof scala.Long)
+ return RunTime.box_cvalue((char)((scala.Long)o).value);
+ else if (o instanceof scala.Int)
+ return RunTime.box_cvalue((char)((scala.Int)o).value);
+ else if (o instanceof scala.Short)
+ return RunTime.box_cvalue((char)((scala.Short)o).value);
+ else if (o instanceof scala.Byte)
+ return RunTime.box_cvalue((char)((scala.Byte)o).value);
+ else
+ throw new ClassCastException();
}
public Object defaultValue() { return ZERO; }
public boolean isSameAsJavaType(Class that) {
diff --git a/sources/scala/runtime/types/TypeDouble.java b/sources/scala/runtime/types/TypeDouble.java
index bf8537c162..0bc22709ee 100644
--- a/sources/scala/runtime/types/TypeDouble.java
+++ b/sources/scala/runtime/types/TypeDouble.java
@@ -18,9 +18,22 @@ public public class TypeDouble extends ValueType {
private final scala.Double ZERO = RunTime.box_dvalue(0.0);
public Object cast(Object o) {
assert scala.runtime.types.Statistics.incTypeCast();
- if (! (o == null || o instanceof scala.Double))
- throw new ClassCastException(); // TODO error message
- return o;
+ if (o == null || o instanceof scala.Double)
+ return o;
+ else if (o instanceof scala.Float)
+ return RunTime.box_dvalue(((scala.Float)o).value);
+ else if (o instanceof scala.Long)
+ return RunTime.box_dvalue(((scala.Long)o).value);
+ else if (o instanceof scala.Int)
+ return RunTime.box_dvalue(((scala.Int)o).value);
+ else if (o instanceof scala.Short)
+ return RunTime.box_dvalue(((scala.Short)o).value);
+ else if (o instanceof scala.Char)
+ return RunTime.box_dvalue(((scala.Char)o).value);
+ else if (o instanceof scala.Byte)
+ return RunTime.box_dvalue(((scala.Byte)o).value);
+ else
+ throw new ClassCastException();
}
public Object defaultValue() { return ZERO; }
public boolean isSameAsJavaType(Class that) {
diff --git a/sources/scala/runtime/types/TypeFloat.java b/sources/scala/runtime/types/TypeFloat.java
index ea998bd71a..5f0e18898c 100644
--- a/sources/scala/runtime/types/TypeFloat.java
+++ b/sources/scala/runtime/types/TypeFloat.java
@@ -18,9 +18,22 @@ public class TypeFloat extends ValueType {
private final scala.Float ZERO = RunTime.box_fvalue(0.0f);
public Object cast(Object o) {
assert scala.runtime.types.Statistics.incTypeCast();
- if (! (o == null || o instanceof scala.Float))
- throw new ClassCastException(); // TODO error message
- return o;
+ if (o == null || o instanceof scala.Float)
+ return o;
+ else if (o instanceof scala.Double)
+ return RunTime.box_fvalue((float)((scala.Double)o).value);
+ else if (o instanceof scala.Long)
+ return RunTime.box_fvalue(((scala.Long)o).value);
+ else if (o instanceof scala.Int)
+ return RunTime.box_fvalue(((scala.Int)o).value);
+ else if (o instanceof scala.Short)
+ return RunTime.box_fvalue(((scala.Short)o).value);
+ else if (o instanceof scala.Char)
+ return RunTime.box_fvalue(((scala.Char)o).value);
+ else if (o instanceof scala.Byte)
+ return RunTime.box_fvalue(((scala.Byte)o).value);
+ else
+ throw new ClassCastException();
}
public Object defaultValue() { return ZERO; }
public boolean isSameAsJavaType(Class that) {
diff --git a/sources/scala/runtime/types/TypeInt.java b/sources/scala/runtime/types/TypeInt.java
index 129a8f0c87..3c29b70c0a 100644
--- a/sources/scala/runtime/types/TypeInt.java
+++ b/sources/scala/runtime/types/TypeInt.java
@@ -19,9 +19,22 @@ public class TypeInt extends ValueType {
private final Int ZERO = RunTime.box_ivalue(0);
public Object cast(Object o) {
assert scala.runtime.types.Statistics.incTypeCast();
- if (! (o == null || o instanceof scala.Int))
- throw new ClassCastException(); // TODO error message
- return o;
+ if (o == null || o instanceof scala.Int)
+ return o;
+ else if (o instanceof scala.Double)
+ return RunTime.box_ivalue((int)((scala.Double)o).value);
+ else if (o instanceof scala.Float)
+ return RunTime.box_ivalue((int)((scala.Float)o).value);
+ else if (o instanceof scala.Long)
+ return RunTime.box_ivalue((int)((scala.Long)o).value);
+ else if (o instanceof scala.Short)
+ return RunTime.box_ivalue(((scala.Short)o).value);
+ else if (o instanceof scala.Char)
+ return RunTime.box_ivalue(((scala.Char)o).value);
+ else if (o instanceof scala.Byte)
+ return RunTime.box_ivalue(((scala.Byte)o).value);
+ else
+ throw new ClassCastException();
}
public Object defaultValue() { return ZERO; }
public boolean isSameAsJavaType(Class that) {
diff --git a/sources/scala/runtime/types/TypeLong.java b/sources/scala/runtime/types/TypeLong.java
index 2e0381fb0f..cc03d72e8f 100644
--- a/sources/scala/runtime/types/TypeLong.java
+++ b/sources/scala/runtime/types/TypeLong.java
@@ -18,9 +18,22 @@ public class TypeLong extends ValueType {
private final scala.Long ZERO = RunTime.box_lvalue(0l);
public Object cast(Object o) {
assert scala.runtime.types.Statistics.incTypeCast();
- if (! (o == null || o instanceof scala.Long))
- throw new ClassCastException(); // TODO error message
- return o;
+ if (o == null || o instanceof scala.Long)
+ return o;
+ else if (o instanceof scala.Double)
+ return RunTime.box_lvalue((long)((scala.Double)o).value);
+ else if (o instanceof scala.Float)
+ return RunTime.box_lvalue((long)((scala.Float)o).value);
+ else if (o instanceof scala.Int)
+ return RunTime.box_lvalue(((scala.Int)o).value);
+ else if (o instanceof scala.Short)
+ return RunTime.box_lvalue(((scala.Short)o).value);
+ else if (o instanceof scala.Char)
+ return RunTime.box_lvalue(((scala.Char)o).value);
+ else if (o instanceof scala.Byte)
+ return RunTime.box_lvalue(((scala.Byte)o).value);
+ else
+ throw new ClassCastException();
}
public Object defaultValue() { return ZERO; }
public boolean isSameAsJavaType(Class that) {
diff --git a/sources/scala/runtime/types/TypeShort.java b/sources/scala/runtime/types/TypeShort.java
index e6abb617e0..286a518596 100644
--- a/sources/scala/runtime/types/TypeShort.java
+++ b/sources/scala/runtime/types/TypeShort.java
@@ -18,9 +18,22 @@ public class TypeShort extends ValueType {
private final scala.Short ZERO = RunTime.box_svalue((short)0);
public Object cast(Object o) {
assert scala.runtime.types.Statistics.incTypeCast();
- if (! (o == null || o instanceof scala.Short))
- throw new ClassCastException(); // TODO error message
- return o;
+ if (o == null || o instanceof scala.Short)
+ return o;
+ else if (o instanceof scala.Double)
+ return RunTime.box_svalue((short)((scala.Double)o).value);
+ else if (o instanceof scala.Float)
+ return RunTime.box_svalue((short)((scala.Float)o).value);
+ else if (o instanceof scala.Long)
+ return RunTime.box_svalue((short)((scala.Long)o).value);
+ else if (o instanceof scala.Int)
+ return RunTime.box_svalue((short)((scala.Int)o).value);
+ else if (o instanceof scala.Char)
+ return RunTime.box_svalue((short)((scala.Char)o).value);
+ else if (o instanceof scala.Byte)
+ return RunTime.box_svalue(((scala.Byte)o).value);
+ else
+ throw new ClassCastException();
}
public Object defaultValue() { return ZERO; }
public boolean isSameAsJavaType(Class that) {