[Mono-bugs] [Bug 68914][Nor] New - Assignment bugs.

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Thu, 28 Oct 2004 19:47:51 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by miguel@ximian.com.

http://bugzilla.ximian.com/show_bug.cgi?id=68914

--- shadow/68914	2004-10-28 19:47:51.000000000 -0400
+++ shadow/68914.tmp.24939	2004-10-28 19:47:51.000000000 -0400
@@ -0,0 +1,87 @@
+Bug#: 68914
+Product: Mono: Compilers
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: C#
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: miguel@ximian.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Assignment bugs.
+
+Currently on assignment we enter this path:
+
+			if (source is New && target_type.IsValueType &&
+			    (target.eclass != ExprClass.IndexerAccess) && (target.eclass !=
+ExprClass.PropertyAccess)){
+
+That `new' is effectively not checking if the result can be stored in 
+the provided value type, so it is possible to write
+
+char a = new Point ()
+
+Now things get more complicated in the presence of implicit conversions,
+as we are not running the code in this code path to do the implicit
+conversion, and `New' is not prepared to deal with this case, so
+we never call the implicit conversion operator.
+
+The following program shows this:
+using System;
+struct PointF {
+	public float fa, fb;
+	
+	public PointF (float a, float b)
+	{
+		fa = a;
+		fb = b;
+	}
+}
+
+struct Point {
+	int ia, ib;
+	
+	public static implicit operator PointF (Point pt)
+	{
+		return new PointF (pt.ia, pt.ib);
+	}
+
+	public Point (int a, int b)
+	{
+		Console.WriteLine ("Initialized with {0} and {1}", a, b);
+		ia = a;
+		ib = b;
+	}
+}
+
+class Axis {
+	public PointF value;
+	
+}
+
+class Test {
+	
+	static void Main ()
+	{
+		Axis a = new Axis ();
+
+		a.value = new Point (1, 2);
+		Console.WriteLine ("Value {0} and {1} (should be 1 and 2)", a.value.fa,
+a.value.fb);
+	}
+}
+
+Although this is easily solvable (generate a temporary variable if 
+ImplicitConversionRequired produces a non-IMemoryLocation), it might
+be best to make New know about UserCast, so we can produce:
+
+newobj valuetype
+call   op_Implicit (...)
+
+Probably New should know about UserCast