Fix cs0029-6.cs and gcs0029-2.cs (regression)
authorRaja R Harinath <harinath@hurrynot.org>
Wed, 17 Jan 2007 12:46:29 +0000 (12:46 -0000)
committerRaja R Harinath <harinath@hurrynot.org>
Wed, 17 Jan 2007 12:46:29 +0000 (12:46 -0000)
* ecore.cs (EmptyConstantCast.ConvertImplicitly): Check that
there's an implicit conversion from the current type to the target
type before converting the underlying constant.

svn path=/trunk/mcs/; revision=71183

mcs/errors/cs0029-6.cs [new file with mode: 0644]
mcs/mcs/ChangeLog
mcs/mcs/ecore.cs

diff --git a/mcs/errors/cs0029-6.cs b/mcs/errors/cs0029-6.cs
new file mode 100644 (file)
index 0000000..aaeca67
--- /dev/null
@@ -0,0 +1,10 @@
+// CS0029: Cannot implicitly convert type `T' to `int*'
+// Line : 8
+// Compiler options: -unsafe
+
+class T {
+       static unsafe void Main ()
+       {
+               int *a = (T) null;
+       }
+}
index 10becaf7af65d089c6689ce9f1d1f2ace657fa86..0fa6e89674ce4443d79b3150bac821e2cd20d4fb 100644 (file)
@@ -1,3 +1,10 @@
+2007-01-17  Raja R Harinath  <rharinath@novell.com>
+
+       Fix cs0029-6.cs and gcs0029-2.cs (regression)
+       * ecore.cs (EmptyConstantCast.ConvertImplicitly): Check that
+       there's an implicit conversion from the current type to the target
+       type before converting the underlying constant.
+
 2007-01-16  Marek Safar  <marek.safar@gmail.com>
 
        * const.cs (ResolveValue): Updated after constant conversion was made more
index d9a19675ada9aa6c1f5637e11198bfe090aeb16a..28963c6dbbaab363aaf74ab7b162e857048f3765 100644 (file)
@@ -1393,6 +1393,7 @@ namespace Mono.CSharp {
 
                public override Constant ConvertExplicitly (bool inCheckedContext, Type target_type)
                {
+                       // FIXME: check that 'type' can be converted to 'target_type' first
                        return child.ConvertExplicitly (inCheckedContext, target_type);
                }
 
@@ -1401,13 +1402,11 @@ namespace Mono.CSharp {
                        return child.Increment ();
                }
 
-               public override bool IsDefaultValue
-               {
+               public override bool IsDefaultValue {
                        get { return child.IsDefaultValue; }
                }
 
-               public override bool IsNegative
-               {
+               public override bool IsNegative {
                        get { return child.IsNegative; }
                }
 
@@ -1416,9 +1415,12 @@ namespace Mono.CSharp {
                        child.Emit (ec);
                }
 
-               public override Constant ConvertImplicitly (Type type)
+               public override Constant ConvertImplicitly (Type target_type)
                {
-                       return child.ConvertImplicitly (type);
+                       // FIXME: Do we need to check user conversions?
+                       if (!Convert.ImplicitStandardConversionExists (this, target_type))
+                               return null;
+                       return child.ConvertImplicitly (target_type);
                }
        }