Better messages than a throw
[mono.git] / mcs / mcs / iterators.cs
index 06c92a90c71dfc6f2542ae1a94dad3c7d2dc20ed..e8a57c1775449e3463f2689316439d5417639347 100644 (file)
@@ -8,7 +8,7 @@
 //
 // TODO:
 //    Flow analysis for Yield.
-//    Emit calls to parent object constructor.
+//    Emit calls to base object constructor.
 //
 // Generics note:
 //    Current should be defined to return T, and IEnumerator.Current returns object
@@ -46,6 +46,10 @@ namespace Mono.CSharp {
                                              "finally clause");
                                return false;
                        }
+                       if (ec.InUnsafe) {
+                               Report.Error (1629, loc, "Unsafe code may not appear in iterators");
+                               return false;
+                       }
                        if (ec.CurrentBranching.InCatch ()){
                                Report.Error (1631, loc, "Cannot yield in the body of a " +
                                              "catch clause");
@@ -352,7 +356,7 @@ namespace Mono.CSharp {
                                 Type [] param_types, InternalParameters parameters,
                                 int modifiers, ToplevelBlock block, Location loc)
                        : base (container.NamespaceEntry, container, MakeProxyName (name),
-                               Modifiers.PRIVATE, null, loc)
+                               (modifiers & Modifiers.UNSAFE) | Modifiers.PRIVATE, null, loc)
                {
                        this.container = container;
                        this.return_type = return_type;
@@ -369,6 +373,8 @@ namespace Mono.CSharp {
 
                public bool DefineIterator ()
                {
+                       ec = new EmitContext (this, Mono.CSharp.Location.Null, null, null, ModFlags);
+
                        if (!CheckType (return_type)) {
                                Report.Error (
                                        1624, Location,
@@ -716,6 +722,11 @@ namespace Mono.CSharp {
                                this.field = field;
                        }
 
+                       public override Expression DoResolveLValue (EmitContext ec, Expression right_side)
+                       {
+                               return DoResolve (ec);
+                       }
+
                        public override Expression DoResolve (EmitContext ec)
                        {
                                FieldExpr fexpr = new FieldExpr (field.FieldBuilder, loc);
@@ -750,6 +761,8 @@ namespace Mono.CSharp {
                                if (iterator.is_static)
                                        code_flags |= Modifiers.STATIC;
 
+                               code_flags |= iterator.ModFlags & Modifiers.UNSAFE;
+
                                EmitContext new_ec = new EmitContext (
                                        iterator.container, loc, ec.ig,
                                        TypeManager.int32_type, code_flags);