[mcs] Extend intermediate value modification checks on generic value types
authorMarek Safar <marek.safar@gmail.com>
Wed, 9 Jul 2014 16:32:55 +0000 (18:32 +0200)
committerMarek Safar <marek.safar@gmail.com>
Wed, 9 Jul 2014 16:32:55 +0000 (18:32 +0200)
mcs/errors/cs1650-3.cs [new file with mode: 0644]
mcs/mcs/ecore.cs

diff --git a/mcs/errors/cs1650-3.cs b/mcs/errors/cs1650-3.cs
new file mode 100644 (file)
index 0000000..e0cfa0c
--- /dev/null
@@ -0,0 +1,19 @@
+// CS1650: Fields of static readonly field `C<T>.t' cannot be assigned to (except in a static constructor or a variable initializer)
+// Line: 17
+
+using System;
+
+interface I
+{
+       int X { get; set; }
+}
+
+class C<T> where T : struct, I
+{
+       static readonly T t;
+
+       public static void Foo ()
+       {
+               t.X = 42;
+       }
+}
index 9f30705a6850ceed895dc71783889c65eb0e3485..9ae68e4f19d764339745d2dc37d4d12549cbddbd 100644 (file)
@@ -3367,7 +3367,7 @@ namespace Mono.CSharp {
                        //
                        // Check intermediate value modification which won't have any effect
                        //
-                       if (rhs != null && InstanceExpression.Type.IsStruct) {
+                       if (rhs != null && TypeSpec.IsValueType (InstanceExpression.Type)) {
                                var fexpr = InstanceExpression as FieldExpr;
                                if (fexpr != null) {
                                        if (!fexpr.Spec.IsReadOnly || rc.HasAny (ResolveContext.Options.FieldInitializerScope | ResolveContext.Options.ConstructorScope))