2001-10-05 Miguel de Icaza <miguel@ximian.com>
authorMiguel de Icaza <miguel@gnome.org>
Fri, 5 Oct 2001 17:03:10 +0000 (17:03 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Fri, 5 Oct 2001 17:03:10 +0000 (17:03 -0000)
* expression.cs: Implicity convert the result from UserCast.

Include the test from Ravi that exhibits the bug.

New classes from Toelen.

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

mcs/mcs/ChangeLog
mcs/mcs/codegen.cs
mcs/mcs/expression.cs
mcs/tests/makefile
mcs/tests/test-17.cs [new file with mode: 0755]

index 5c944a8e549885456a8179eeaa2fa08189284e08..290bca3ed9ef58ac28305fe112644181cf1b44bf 100755 (executable)
@@ -1,3 +1,7 @@
+2001-10-05  Miguel de Icaza  <miguel@ximian.com>
+
+       * expression.cs: Implicity convert the result from UserCast.
+
 2001-10-05  Ravi Pratap  <ravi@ximian.com>
 
        * expression.cs (Expression::FindMostEncompassingType): Fix bug which
index cd3035c1d44e1b6d505d752f7e687a680c37a58c..12fdd8ab2e53ed1fd561e196b0213e62ba311721 100755 (executable)
@@ -31,13 +31,20 @@ namespace CIR {
 
                        return name;
                }
+
+               string TrimExt (string name)
+               {
+                       int pos = name.LastIndexOf (".");
+
+                       return name.Substring (0, pos);
+               }
                
                public CodeGen (string name, string output)
                {
                        AssemblyName an;
                        
                        an = new AssemblyName ();
-                       an.Name = name;
+                       an.Name = TrimExt (name);
                        current_domain = AppDomain.CurrentDomain;
                        assembly_builder = current_domain.DefineDynamicAssembly (
                                an, AssemblyBuilderAccess.RunAndSave);
@@ -214,6 +221,7 @@ namespace CIR {
 
                bool ProbeCollectionType (Type t)
                {
+                       
                        return true;
                }
                
index 75bb6f82ad4977db7d908598a31359b514db2276..75b4aa27ea8bad2ff767b23d6f2e5b5ce4b07418 100755 (executable)
@@ -866,6 +866,7 @@ namespace CIR {
                {
                        Expression mg1 = null, mg2 = null, mg3 = null, mg4 = null;
                        Expression mg5 = null, mg6 = null, mg7 = null, mg8 = null;
+                       Expression e;
                        MethodBase method = null;
                        Type source_type = source.Type;
 
@@ -952,10 +953,20 @@ namespace CIR {
                                        return null;
                                }
                                
+                               //
+                               // This will do the conversion to the best match that we
+                               // found.  Now we need to perform an implict standard conversion
+                               // if the best match was not the type that we were requested
+                               // by target.
+                               //
+                               e =  new UserCast ((MethodInfo) method, source, most_specific_source,
+                                                  most_specific_target, look_for_explicit);
 
-                               return new UserCast ((MethodInfo) method, source, most_specific_source,
-                                                    most_specific_target, look_for_explicit);
-
+                               if (e.Type != target){
+                                       e = ConvertImplicitStandard (tc, e, target, l);
+                                       return e;
+                               } else
+                                       return e;
                        }
                        
                        return null;
index bf510bd250512523f7dd8a197fc049a84d0ad189..adcfe165db9e05ee80f2af306c8bdbb4f85298d4 100755 (executable)
@@ -3,7 +3,7 @@ CSC=csc
 
 TEST_SOURCES = \
        test-1 test-2 test-3 test-4 test-6 test-7 test-8 test-9 test-10 \
-       test-11 test-12 test-13 test-16 test-20
+       test-11 test-12 test-13 test-16 test-17 test-20
 
 TEST_NOPASS = \
        test-5
diff --git a/mcs/tests/test-17.cs b/mcs/tests/test-17.cs
new file mode 100755 (executable)
index 0000000..c6e2a95
--- /dev/null
@@ -0,0 +1,45 @@
+//
+// This test excercises user defined conversions and an implicit
+// conversion to a type afterwards.
+//
+// 
+using System;
+
+class Blah {
+
+ public static int Main ()
+ {
+  Blah k = new Blah ();
+
+  float f = k;
+
+  if (f == 2){
+   Console.WriteLine ("Best implicit operator selected correctly");
+   return 0;
+  }
+  return 1;
+
+ }
+
+ public static implicit operator byte (Blah i)
+ {
+  Console.WriteLine ("Blah->byte");
+  return 0;
+ }
+
+
+ public static implicit operator short (Blah i)
+ {
+  Console.WriteLine ("Blah->short");
+  return 1;
+ }
+
+ public static implicit operator int (Blah i)
+ {
+  Console.WriteLine ("Blah->int");
+  return 2;
+ }
+
+
+}
+