2005-04-11 Marek Safar <marek.safar@seznam.cz>
authorMarek Safar <marek.safar@gmail.com>
Mon, 11 Apr 2005 09:25:59 +0000 (09:25 -0000)
committerMarek Safar <marek.safar@gmail.com>
Mon, 11 Apr 2005 09:25:59 +0000 (09:25 -0000)
Fix# 74565
* class.cs (TypeContainer.CircularDepException) New nested
exception class.
(GetPartialBases, GetNormalBases, GetClassBases): Removed error.
(TypeContainer.DefineType): Removed error, reset InTransit before
exit.
(Class.DefineType): Throw exception when is in Transit.
Catch exception and report error.
(Struct.DefineType): Throw exception when is in Transit.
Catch exception and report error.
(Interface.DefineType): Throw exception when is in Transit.
Catch exception and report error.

* codegen.cs: Add InCatch,InFinally to EmitContext to easily
handle nested exception handlers.

* flowanalysis.cs (InTryWithCatch): New method, search for try with
a catch.

* iterators.cs (Yield.CheckContext): Add CS1626 report. Updated
InFinally and InCatch storage.

* statement.cs (Throw.Resolve): Use InCatch, InFinally from ec.
(Catch.Resolve): Set and Restore ec.InCatch.
(Try.Resolve): Set and Restore ec.InFinally.
(Try.HasCatch): True when try has catch.

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

mcs/mcs/ChangeLog
mcs/mcs/class.cs
mcs/mcs/codegen.cs
mcs/mcs/decl.cs
mcs/mcs/expression.cs
mcs/mcs/flowanalysis.cs
mcs/mcs/iterators.cs
mcs/mcs/statement.cs

index 102810679b00633e15c7fb975b7cf8a0cc22bc6e..363107858bdece16f39f1e312e9efa839af57491 100644 (file)
@@ -1,3 +1,32 @@
+2005-04-11  Marek Safar  <marek.safar@seznam.cz>
+
+       Fix# 74565
+       * class.cs (TypeContainer.CircularDepException) New nested
+       exception class.
+       (GetPartialBases, GetNormalBases, GetClassBases): Removed error.
+       (TypeContainer.DefineType): Removed error, reset InTransit before
+       exit.
+       (Class.DefineType): Throw exception when is in Transit.
+       Catch exception and report error.
+       (Struct.DefineType): Throw exception when is in Transit.
+       Catch exception and report error.
+       (Interface.DefineType): Throw exception when is in Transit.
+       Catch exception and report error.
+       
+       * codegen.cs: Add InCatch,InFinally to EmitContext to easily
+       handle nested exception handlers.
+
+       * flowanalysis.cs (InTryWithCatch): New method, search for try with
+       a catch.
+       
+       * iterators.cs (Yield.CheckContext): Add CS1626 report. Updated
+       InFinally and InCatch storage.
+       
+       * statement.cs (Throw.Resolve): Use InCatch, InFinally from ec.
+       (Catch.Resolve): Set and Restore ec.InCatch.
+       (Try.Resolve): Set and Restore ec.InFinally.
+       (Try.HasCatch): True when try has catch.
+
 2005-04-10  Miguel de Icaza  <miguel@novell.com>
 
        * driver.cs (MainDriver): Stop processing if the CLS stage found
 
 2005-03-15  Marek Safar  <marek.safar@seznam.cz>
 
-       * class.cs (TypeContainer.CircularDepException) New nested
-       (MethodCore.CheckBase): Report CS1715 for properties and indexers.
+       * class.cs (MethodCore.CheckBase): Report CS1715 for properties and
+       indexers.
 
        * cs-parser.jay: Reports CS1527 for any namespace element.
 
index 4b5ef559ec42e1149fe2e555f4b3b965644694e0..c7670a1cefce374ed95aace4763d3ff73357c9d1 100644 (file)
@@ -64,6 +64,15 @@ namespace Mono.CSharp {
        /// </summary>
        public abstract class TypeContainer : DeclSpace, IMemberContainer {
 
+               protected class CircularDepException: Exception
+               {
+                       public TypeContainer Container;
+                       public CircularDepException (TypeContainer tc)
+                       {
+                               Container = tc;
+                       }
+               }
+
                public class MemberCoreArrayList: ArrayList
                {
                        /// <summary>
@@ -464,6 +473,9 @@ namespace Mono.CSharp {
                MemberCache member_cache;
 
                public const string DefaultIndexerName = "Item";
+
+               // This is used to catch recursive definitions in declarations.
+               protected bool InTransit;
                
                public TypeContainer (NamespaceEntry ns, TypeContainer parent, MemberName name,
                                      Attributes attrs, Kind kind, Location l)
@@ -933,7 +945,7 @@ namespace Mono.CSharp {
 
                public abstract PendingImplementation GetPendingImplementations ();
 
-               TypeExpr[] GetPartialBases (out TypeExpr base_class, out bool error)
+               TypeExpr[] GetPartialBases (out TypeExpr base_class)
                {
                        ArrayList ifaces = new ArrayList ();
 
@@ -944,8 +956,8 @@ namespace Mono.CSharp {
                                TypeExpr new_base_class;
                                TypeExpr[] new_ifaces;
 
-                               new_ifaces = part.GetClassBases (out new_base_class, out error);
-                               if (error)
+                               new_ifaces = part.GetClassBases (out new_base_class);
+                               if (new_ifaces == null && base_type != null)
                                        return null;
 
                                if ((base_class != null) && (new_base_class != null) &&
@@ -958,7 +970,6 @@ namespace Mono.CSharp {
                                        if (!Location.IsNull (base_loc))
                                                Report.LocationOfPreviousError (base_loc);
 
-                                       error = true;
                                        return null;
                                }
 
@@ -984,14 +995,12 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       error = false;
-
                        TypeExpr[] retval = new TypeExpr [ifaces.Count];
                        ifaces.CopyTo (retval, 0);
                        return retval;
                }
 
-               TypeExpr[] GetNormalBases (out TypeExpr base_class, out bool error)
+               TypeExpr[] GetNormalBases (out TypeExpr base_class)
                {
                        base_class = null;
 
@@ -1003,7 +1012,6 @@ namespace Mono.CSharp {
                                        (Expression) Bases [0], false, Location);
 
                                if (name == null){
-                                       error = true;
                                        return null;
                                }
 
@@ -1020,14 +1028,12 @@ namespace Mono.CSharp {
                        for (i = start, j = 0; i < count; i++, j++){
                                TypeExpr resolved = ResolveBaseTypeExpr ((Expression) Bases [i], false, Location);
                                if (resolved == null) {
-                                       error = true;
                                        return null;
                                }
                                
                                ifaces [j] = resolved;
                        }
 
-                       error = false;
                        return ifaces;
                }
 
@@ -1041,35 +1047,31 @@ namespace Mono.CSharp {
                ///   The @base_class argument is set to the base object or null
                ///   if this is `System.Object'. 
                /// </summary>
-               TypeExpr [] GetClassBases (out TypeExpr base_class, out bool error)
+               TypeExpr [] GetClassBases (out TypeExpr base_class)
                {
                        int i;
 
-                       error = false;
-
                        TypeExpr[] ifaces;
 
                        if (parts != null)
-                               ifaces = GetPartialBases (out base_class, out error);
+                               ifaces = GetPartialBases (out base_class);
                        else if (Bases == null){
                                base_class = null;
                                return null;
                        } else
-                               ifaces = GetNormalBases (out base_class, out error);
+                               ifaces = GetNormalBases (out base_class);
 
-                       if (error)
+                       if (ifaces == null)
                                return null;
 
                        if ((base_class != null) && (Kind == Kind.Class)){
 
                                if (base_class.Type.IsArray || base_class.Type.IsPointer) {
                                        Report.Error (1521, base_class.Location, "Invalid base type");
-                                       error = true;
                                        return null;
                                }
 
                                if (base_class.IsSealed){
-                                       error = true;
                                        Report.SymbolRelatedToPreviousError (base_class.Type);
                                        if (base_class.Type.IsAbstract) {
                                                Report.Error (709, Location, "'{0}': Cannot derive from static class", GetSignatureForError ());
@@ -1083,7 +1085,6 @@ namespace Mono.CSharp {
                                        Report.Error (644, Location,
                                                      "`{0}' cannot inherit from special class `{1}'",
                                                      Name, base_class.Name);
-                                       error = true;
                                        return null;
                                }
 
@@ -1106,13 +1107,9 @@ namespace Mono.CSharp {
                                TypeExpr iface = (TypeExpr) ifaces [i];
 
                                if (!iface.IsInterface) {
-                                       error = true;
                                        if (Kind != Kind.Class) {
-                                               string what = Kind == Kind.Struct ? "Struct" : "Interface";
-                                               
-                                               Report.Error (527, Location,
-                                                             "In {0} `{1}', type `{2}' is not "+
-                                                             "an interface", what, Name, iface.Name);
+                                               // TODO: location of symbol related ....
+                                               Error_TypeInListIsNotInterface (Location, iface.FullName);
                                        }
                                        else if (base_class != null)
                                                Report.Error (1721, Location,
@@ -1123,7 +1120,7 @@ namespace Mono.CSharp {
                                                              "In Class `{0}', `{1}' is not " +
                                                              "an interface, a base class must be listed first", Name, iface.Name);
                                        }
-                                       continue;
+                                       return null;
                                }
 
                                for (int x = 0; x < i; x++) {
@@ -1131,7 +1128,7 @@ namespace Mono.CSharp {
                                                Report.Error (528, Location,
                                                              "`{0}' is already listed in " +
                                                              "interface list", iface.Name);
-                                               error = true;
+                                               return null;
                                        }
                                }
 
@@ -1142,18 +1139,17 @@ namespace Mono.CSharp {
                                                      "interface `{0}' is less accessible " +
                                                      "than interface `{1}'", iface.Name,
                                                      Name);
-                                       error = true;
+                                       return null;
                                }
                        }
-
-                       if (error)
-                               return null;
-
                        return ifaces;
                }
 
-               bool error = false;
-               
+               protected void Error_TypeInListIsNotInterface (Location loc, string type)
+               {
+                       Report.Error (527, loc, "'{0}': type in interface list is not an interface", type);
+               }
+
                //
                // Defines the type in the appropriate ModuleBuilder or TypeBuilder.
                //
@@ -1161,21 +1157,14 @@ namespace Mono.CSharp {
                {
                        if (TypeBuilder != null)
                                return TypeBuilder;
-
-                       if (error)
-                               return null;
-
-                       if (InTransit) {
-                               Report.Error (146, Location, "Class definition is circular: `{0}'", Name);
-                               error = true;
-                               return null;
-                       }
                        
                        InTransit = true;
 
-                       TypeExpr[] iface_exprs = GetClassBases (out base_type, out error);
-                       if (error)
+                       TypeExpr[] iface_exprs = GetClassBases (out base_type);
+                       if (iface_exprs == null && base_type != null) {
+                               InTransit = false;
                                return null;
+                       }
 
                        if (base_type == null) {
                                if (Kind == Kind.Class){
@@ -1206,7 +1195,7 @@ namespace Mono.CSharp {
                                //        However, if Parent == RootContext.Tree.Types, its NamespaceEntry will be null.
                                ptype = base_type.ResolveType (TypeResolveEmitContext);
                                if (ptype == null) {
-                                       error = true;
+                                       InTransit = false;
                                        return null;
                                }
                        }
@@ -1214,7 +1203,7 @@ namespace Mono.CSharp {
                        try {
                                if (IsTopLevel){
                                        if (TypeManager.NamespaceClash (Name, Location)) {
-                                               error = true;
+                                               InTransit = false;
                                                return null;
                                        }
                                
@@ -1224,8 +1213,10 @@ namespace Mono.CSharp {
                                
                                } else {
                                        TypeBuilder builder = Parent.TypeBuilder;
-                                       if (builder == null)
+                                       if (builder == null) {
+                                               InTransit = false;
                                                return null;
+                                       }
                                
                                        TypeBuilder = builder.DefineNestedType (
                                                Basename, type_attributes, ptype, null);
@@ -1233,6 +1224,7 @@ namespace Mono.CSharp {
                        }
                        catch (ArgumentException) {
                                Report.RuntimeMissingSupport (Location, "static classes");
+                               InTransit = false;
                                return null;
                        }
 
@@ -1269,7 +1261,7 @@ namespace Mono.CSharp {
                                TypeResolveEmitContext.ContainerType = TypeBuilder;
                                ifaces = TypeManager.ExpandInterfaces (TypeResolveEmitContext, iface_exprs);
                                if (ifaces == null) {
-                                       error = true;
+                                       InTransit = false;
                                        return null;
                                }
 
@@ -1284,12 +1276,12 @@ namespace Mono.CSharp {
                        if (!(this is Iterator))
                                RootContext.RegisterOrder (this); 
 
+                       InTransit = false;
+
                        if (!DefineNestedTypes ()) {
-                               error = true;
                                return null;
                        }
 
-                       InTransit = false;
                        return TypeBuilder;
                }
 
@@ -2793,6 +2785,8 @@ namespace Mono.CSharp {
                        Modifiers.SEALED |
                        Modifiers.UNSAFE;
 
+               bool WasTransitError;
+
                public Class (NamespaceEntry ns, TypeContainer parent, MemberName name, int mod,
                              Attributes attrs, Location l)
                        : base (ns, parent, name, attrs, Kind.Class, l)
@@ -2832,6 +2826,12 @@ namespace Mono.CSharp {
 
                public override TypeBuilder DefineType()
                {
+                       if (InTransit) {
+                               if (WasTransitError)
+                                       return null;
+                               throw new CircularDepException (this);
+                       }
+
                        if ((ModFlags & Modifiers.ABSTRACT) == Modifiers.ABSTRACT && (ModFlags & (Modifiers.SEALED | Modifiers.STATIC)) != 0) {
                                Report.Error (418, Location, "'{0}': an abstract class cannot be sealed or static", GetSignatureForError ());
                                return null;
@@ -2840,7 +2840,16 @@ namespace Mono.CSharp {
                        int accmods = Parent.Parent == null ? Modifiers.INTERNAL : Modifiers.PRIVATE;
                        ModFlags = Modifiers.Check (AllowedModifiersProp, ModFlags, accmods, Location);
 
-                       return base.DefineType ();
+                       try {
+                               return base.DefineType ();
+                       }
+                       catch (CircularDepException e) {
+                               Report.SymbolRelatedToPreviousError (e.Container);
+                               Report.Error (146, Location, "Circular base class dependency involving '{0}' and '{1}'",
+                                       GetSignatureForError (), e.Container.GetSignatureForError ());
+                               WasTransitError = true;
+                               return null;
+                       }
                }
 
                /// Search for at least one defined condition in ConditionalAttribute of attribute class
@@ -2924,12 +2933,33 @@ namespace Mono.CSharp {
                                return base.TypeAttr | DefaultTypeAttributes;
                        }
                }
+
+               public override TypeBuilder DefineType()
+               {
+                       if (InTransit) {
+                               InTransit = false;
+                               throw new CircularDepException (this);
+                       }
+
+                       try {
+                               return base.DefineType ();
+                       }
+                       catch (CircularDepException e) {
+                               InTransit = false;
+                               Report.SymbolRelatedToPreviousError (this);
+                               Error_TypeInListIsNotInterface (e.Container.Location, GetSignatureForError ());
+                               return null;
+                       }
+               }
        }
 
        /// <summary>
        ///   Interfaces
        /// </summary>
        public class Interface : TypeContainer, IMemberContainer {
+
+               bool WasTransitError;
+
                /// <summary>
                ///   Modifiers allowed in a class declaration
                /// </summary>
@@ -2970,6 +3000,27 @@ namespace Mono.CSharp {
                                return base.TypeAttr | DefaultTypeAttributes;
                        }
                }
+
+               public override TypeBuilder DefineType()
+               {
+                       if (InTransit) {
+                               if (WasTransitError) 
+                                       return null;
+                               throw new CircularDepException (this);
+                       }
+
+                       try {
+                               return base.DefineType ();
+                       }
+                       catch (CircularDepException e) {
+                               Report.SymbolRelatedToPreviousError (e.Container);
+                               Report.Error (529, Location, "Inherited interface '{0}' causes a cycle in the interface hierarchy of '{1}'",
+                                       e.Container.GetSignatureForError (), GetSignatureForError ());
+                               WasTransitError = true;
+                               return null;
+                       }
+               }
+
        }
 
        public abstract class MethodCore : MemberBase {
index 4c84e54b7c139c975bc223af27bb221f901090e8..f5a2ba5f9b827af1eaa98a697d94e8c174eb4a6e 100644 (file)
@@ -383,6 +383,9 @@ namespace Mono.CSharp {
                /// </summary>
                public bool InFixedInitializer;
 
+               public bool InCatch;
+               public bool InFinally;
+
                /// <summary>
                ///  Whether we are inside an anonymous method.
                /// </summary>
index c6872ce2d75ac88e101355e192730fa0631d9cda..435c8acbd5c1194a57211cb20aca6ab33f8623c5 100644 (file)
@@ -585,22 +585,6 @@ namespace Mono.CSharp {
                        return (MemberCore)defined_names [name];
                }
                
-               bool in_transit = false;
-               
-               /// <summary>
-               ///   This function is used to catch recursive definitions
-               ///   in declarations.
-               /// </summary>
-               public bool InTransit {
-                       get {
-                               return in_transit;
-                       }
-
-                       set {
-                               in_transit = value;
-                       }
-               }
-               
                // 
                // root_types contains all the types.  All TopLevel types
                // hence have a parent that points to `root_types', that is
index 3ce28b8f3a8e530c64f50e10d02d48d86ea11352..2404bf38e4f6cbb16f24b65a4e7217a3de7e56f4 100644 (file)
@@ -8643,8 +8643,7 @@ namespace Mono.CSharp {
                                return null;
                        }
 
-                       if (ec.CurrentBranching.InCatch () ||
-                           ec.CurrentBranching.InFinally (true)) {
+                       if (ec.InCatch || ec.InFinally) {
                                Error (255,
                                       "stackalloc can not be used in a catch or finally block");
                                return null;
index 4a3515a0bc28369c4000468b2f662c1bde2f3318..caad299da7e99edcf99afcbacbe62b7f205733d5 100644 (file)
@@ -1171,29 +1171,11 @@ namespace Mono.CSharp
                                return false;
                }
 
-               //
-               // Checks whether we're in a `catch' block.
-               //
-               public virtual bool InCatch ()
+               public virtual bool InTryWithCatch ()
                {
                        if (Parent != null)
-                               return Parent.InCatch ();
-                       else
-                               return false;
-               }
-
-               //
-               // Checks whether we're in a `finally' block.
-               //
-               public virtual bool InFinally (bool is_return)
-               {
-                       if (!is_return &&
-                           ((Type == BranchingType.Loop) || (Type == BranchingType.Switch)))
-                               return false;
-                       else if (Parent != null)
-                               return Parent.InFinally (is_return);
-                       else
-                               return false;
+                               return Parent.InTryWithCatch ();
+                       return false;
                }
 
                public virtual bool InLoop ()
@@ -1383,7 +1365,6 @@ namespace Mono.CSharp
                UsageVector finally_vector;
                UsageVector finally_origins;
                bool emit_finally;
-               bool in_try;
 
                public FlowBranchingException (FlowBranching parent,
                                               ExceptionStatement stmt)
@@ -1399,15 +1380,12 @@ namespace Mono.CSharp
                        if (sibling.Type == SiblingType.Try) {
                                sibling.Next = catch_vectors;
                                catch_vectors = sibling;
-                               in_try = true;
                        } else if (sibling.Type == SiblingType.Catch) {
                                sibling.Next = catch_vectors;
                                catch_vectors = sibling;
-                               in_try = false;
                        } else if (sibling.Type == SiblingType.Finally) {
                                sibling.MergeFinallyOrigins (finally_origins);
                                finally_vector = sibling;
-                               in_try = false;
                        } else
                                throw new InvalidOperationException ();
 
@@ -1423,14 +1401,18 @@ namespace Mono.CSharp
                        return finally_vector == null;
                }
 
-               public override bool InCatch ()
+               public override bool InTryWithCatch ()
                {
-                       return !in_try && (finally_vector == null);
-               }
+                       if (finally_vector == null) {
+                               Try t = stmt as Try;
+                               if (t != null && t.HasCatch)
+                                       return true;
+                       }
 
-               public override bool InFinally (bool is_return)
-               {
-                       return finally_vector != null;
+                       if (Parent != null)
+                               return Parent.InTryWithCatch ();
+
+                       return false;
                }
 
                public override bool BreakCrossesTryCatchBoundary ()
index a81ea1e57d5525c86039c1046bc4680837224531..295f56a536efcc90becf4764b1c42085510a59db 100644 (file)
@@ -41,7 +41,7 @@ namespace Mono.CSharp {
 
                public static bool CheckContext (EmitContext ec, Location loc)
                {
-                       if (ec.CurrentBranching.InFinally (true)){
+                       if (ec.InFinally) {
                                Report.Error (1625, loc, "Cannot yield in the body of a " +
                                              "finally clause");
                                return false;
@@ -50,19 +50,21 @@ namespace Mono.CSharp {
                                Report.Error (1629, loc, "Unsafe code may not appear in iterators");
                                return false;
                        }
-                       if (ec.CurrentBranching.InCatch ()){
+                       if (ec.InCatch){
                                Report.Error (1631, loc, "Cannot yield in the body of a " +
                                              "catch clause");
                                return false;
                        }
                        if (ec.CurrentAnonymousMethod != null){
-                               Report.Error (1621, loc, "yield statement can not appear inside an anonymoud method");
+                               Report.Error (1621, loc, "The yield statement cannot be used inside anonymous method blocks");
                                return false;
                        }
 
-                       //
-                       // FIXME: Missing check for Yield inside try block that contains catch clauses
-                       //
+                       if (ec.CurrentBranching.InTryWithCatch ()) {
+                               Report.Error (1626, loc, "Cannot yield a value in the body of a " +
+                                       "try block with a catch clause");
+                               return false;
+                       }
                        return true;
                }
                
index cf159fe6cd6cf77d1402d65eb0996e31e0e33f8c..0ce9b01df8d59a1a2cc86440d32be57701bc7f83 100644 (file)
@@ -611,7 +611,7 @@ namespace Mono.CSharp {
                        if (ec.CurrentBranching.InTryOrCatch (true)) {
                                ec.CurrentBranching.AddFinallyVector (vector);
                                in_exc = true;
-                       } else if (ec.CurrentBranching.InFinally (true)) {
+                       } else if (ec.InFinally) {
                                Error (157, "Control can not leave the body of the finally block");
                                return false;
                        } else
@@ -871,13 +871,13 @@ namespace Mono.CSharp {
                                return true;
                        }
 
-                       if (ec.CurrentBranching.InFinally (true)) {
-                               Error (724, "A throw statement with no argument is only allowed in a catch clause nested inside of the innermost catch clause");
+                       if (!ec.InCatch) {
+                               Error (156, "A throw statement with no arguments is not allowed outside of a catch clause");
                                return false;
                        }
 
-                       if (!ec.CurrentBranching.InCatch ()) {
-                               Error (156, "A throw statement with no argument is only allowed in a catch clause");
+                       if (ec.InFinally) {
+                               Error (724, "A throw statement with no argument is only allowed in a catch clause nested inside of the innermost catch clause");
                                return false;
                        }
                        return true;
@@ -909,7 +909,7 @@ namespace Mono.CSharp {
                        if (!ec.CurrentBranching.InLoop () && !ec.CurrentBranching.InSwitch ()){
                                Error (139, "No enclosing loop or switch to continue to");
                                return false;
-                       } else if (ec.CurrentBranching.InFinally (false)) {
+                       } else if (ec.InFinally) {
                                Error (157, "Control can not leave the body of the finally block");
                                return false;
                        } else if (ec.CurrentBranching.InTryOrCatch (false))
@@ -954,7 +954,7 @@ namespace Mono.CSharp {
                        if (!ec.CurrentBranching.InLoop () && !ec.CurrentBranching.InSwitch ()){
                                Error (139, "No enclosing loop to continue to");
                                return false;
-                       } else if (ec.CurrentBranching.InFinally (false)) {
+                       } else if (ec.InFinally) {
                                Error (157, "Control can not leave the body of the finally block");
                                return false;
                        } else if (ec.CurrentBranching.InTryOrCatch (false))
@@ -3587,23 +3587,30 @@ namespace Mono.CSharp {
 
                public override bool Resolve (EmitContext ec)
                {
-                       if (type_expr != null) {
-                               TypeExpr te = type_expr.ResolveAsTypeTerminal (ec, false);
-                               if (te == null)
-                                       return false;
+                       bool was_catch = ec.InCatch;
+                       ec.InCatch = true;
+                       try {
+                               if (type_expr != null) {
+                                       TypeExpr te = type_expr.ResolveAsTypeTerminal (ec, false);
+                                       if (te == null)
+                                               return false;
 
-                               type = te.ResolveType (ec);
+                                       type = te.ResolveType (ec);
 
-                               CheckObsolete (type);
+                                       CheckObsolete (type);
 
-                               if (type != TypeManager.exception_type && !type.IsSubclassOf (TypeManager.exception_type)){
-                                       Error (155, "The type caught or thrown must be derived from System.Exception");
-                                       return false;
-                               }
-                       } else
-                               type = null;
+                                       if (type != TypeManager.exception_type && !type.IsSubclassOf (TypeManager.exception_type)){
+                                               Error (155, "The type caught or thrown must be derived from System.Exception");
+                                               return false;
+                                       }
+                               } else
+                                       type = null;
 
-                       return Block.Resolve (ec);
+                               return Block.Resolve (ec);
+                       }
+                       finally {
+                               ec.InCatch = was_catch;
+                       }
                }
        }
 
@@ -3698,9 +3705,11 @@ namespace Mono.CSharp {
                                                Fini, FlowBranching.SiblingType.Finally);
 
                                Report.Debug (1, "STARTED SIBLING FOR FINALLY", ec.CurrentBranching, vector);
-
+                               bool was_finally = ec.InFinally;
+                               ec.InFinally = true;
                                if (!Fini.Resolve (ec))
                                        ok = false;
+                               ec.InFinally = was_finally;
                        }
 
                        ResolveFinally (branching);
@@ -3766,6 +3775,13 @@ namespace Mono.CSharp {
                                Fini.Emit (ec);
                        }
                }
+
+               public bool HasCatch
+               {
+                       get {
+                               return General != null || Specific.Count > 0;
+                       }
+               }
        }
 
        public class Using : ExceptionStatement {