Author: raja
Date: 2005-10-28 10:16:32 -0400 (Fri, 28 Oct 2005)
New Revision: 52322
Modified:
trunk/mcs/gmcs/ChangeLog
trunk/mcs/gmcs/cfold.cs
trunk/mcs/gmcs/convert.cs
trunk/mcs/gmcs/ecore.cs
trunk/mcs/gmcs/literal.cs
trunk/mcs/tests/known-issues-gmcs
Log:
*** merged revisions from mcs: 52313
Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog 2005-10-28 13:58:16 UTC (rev 52321)
+++ trunk/mcs/gmcs/ChangeLog 2005-10-28 14:16:32 UTC (rev 52322)
@@ -1,3 +1,17 @@
+2005-10-28 Marek Safar <[EMAIL PROTECTED]>
+
+ Fix #76568.
+ * cfold.cs (ConstantFold.BinaryFold): Implemented null cast
+ folding.
+
+ * convert (Convert.ImplicitReferenceConversion): NullCast holds
+ contants only.
+
+ * ecore.cs (NullCast): Child is contant only.
+
+ * literal.cs (NullLiteral.Reduce): null can be converted to any
+ reference type.
+
2005-10-28 Korn�l P�l <[EMAIL PROTECTED]>
* driver.cs: Use Encoding.Default as default code page instead
Modified: trunk/mcs/gmcs/cfold.cs
===================================================================
--- trunk/mcs/gmcs/cfold.cs 2005-10-28 13:58:16 UTC (rev 52321)
+++ trunk/mcs/gmcs/cfold.cs 2005-10-28 14:16:32 UTC (rev 52322)
@@ -174,6 +174,12 @@
static public Expression BinaryFold (EmitContext ec,
Binary.Operator oper,
Constant left, Constant
right, Location loc)
{
+ if (left is NullCast)
+ return BinaryFold (ec, oper,
((NullCast)left).child, right, loc);
+
+ if (right is NullCast)
+ return BinaryFold (ec, oper, left,
((NullCast)right).child, loc);
+
Type lt = left.Type;
Type rt = right.Type;
Type result_type = null;
Modified: trunk/mcs/gmcs/convert.cs
===================================================================
--- trunk/mcs/gmcs/convert.cs 2005-10-28 13:58:16 UTC (rev 52321)
+++ trunk/mcs/gmcs/convert.cs 2005-10-28 14:16:32 UTC (rev 52322)
@@ -29,7 +29,7 @@
//
public static EmitContext ConstantEC = null;
- static Expression TypeParameter_to_Null (Expression expr, Type
target_type,
+ static Expression TypeParameter_to_Null (Constant expr, Type
target_type,
Location loc)
{
if (!TypeParameter_to_Null (target_type)) {
@@ -157,7 +157,7 @@
if (TypeManager.IsValueType (expr_type))
return new BoxedCast (expr,
target_type);
if (expr_type == TypeManager.null_type)
- return new NullCast (expr, target_type);
+ return new NullCast ((Constant)expr,
target_type);
return null;
} else if (TypeManager.IsSubclassOf (expr_type,
target_type)) {
@@ -182,8 +182,14 @@
if (target_type.IsPointer)
return new EmptyCast (NullPointer.Null,
target_type);
- if (!target_type.IsValueType)
- return new NullCast (expr, target_type);
+ if (!target_type.IsValueType) {
+ if (expr is Constant)
+ return new NullCast
((Constant)expr, target_type);
+
+ // I found only one case when it
happens -- Foo () ? null : null;
+ Report.Warning (-100, 1, expr.Location,
"The result of the expression is always `null'");
+ return new NullCast (new NullLiteral
(expr.Location), target_type);
+ }
}
// from any class-type S to any interface-type T.
@@ -1206,7 +1212,7 @@
if (expr is NullLiteral) {
if (target_type.IsGenericParameter)
- return TypeParameter_to_Null (expr,
target_type, loc);
+ return TypeParameter_to_Null
((Constant) expr, target_type, loc);
if (TypeManager.IsNullableType (target_type))
return new Nullable.NullableLiteral
(target_type, loc);
Modified: trunk/mcs/gmcs/ecore.cs
===================================================================
--- trunk/mcs/gmcs/ecore.cs 2005-10-28 13:58:16 UTC (rev 52321)
+++ trunk/mcs/gmcs/ecore.cs 2005-10-28 14:16:32 UTC (rev 52322)
@@ -307,7 +307,7 @@
return;
}
- if (Type != TypeManager.string_type && this is
Constant) {
+ if (Type != TypeManager.string_type && this is Constant
&& !(this is NullCast)) {
Report.Error (31, loc, "Constant value `{0}'
cannot be converted to a `{1}'",
GetSignatureForError (),
TypeManager.CSharpName (target));
return;
@@ -1290,9 +1290,9 @@
// a NullLiteral is still a Constant
//
public class NullCast : Constant {
- protected Expression child;
+ public Constant child;
- public NullCast (Expression child, Type return_type):
+ public NullCast (Constant child, Type return_type):
base (Location.Null)
{
eclass = child.eclass;
Modified: trunk/mcs/gmcs/literal.cs
===================================================================
--- trunk/mcs/gmcs/literal.cs 2005-10-28 13:58:16 UTC (rev 52321)
+++ trunk/mcs/gmcs/literal.cs 2005-10-28 14:16:32 UTC (rev 52322)
@@ -116,7 +116,7 @@
public override Constant Reduce(EmitContext ec, Type
target_type)
{
- if (target_type == TypeManager.string_type)
+ if (!TypeManager.IsValueType (target_type))
return new NullCast (this, target_type);
return null;
Modified: trunk/mcs/tests/known-issues-gmcs
===================================================================
--- trunk/mcs/tests/known-issues-gmcs 2005-10-28 13:58:16 UTC (rev 52321)
+++ trunk/mcs/tests/known-issues-gmcs 2005-10-28 14:16:32 UTC (rev 52322)
@@ -10,5 +10,3 @@
test-67.cs IGNORE # Windows-only test
test-anon-27.cs
test-xml-027.cs
-
-test-10.cs
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches