Handle type hidding via local variables and parameters. Fixes #8383
[mono.git] / mcs / mcs / property.cs
index 3765e77ac64c0da476c7d11b348452aa55a2d687..325b8f118f4bab61e4995812fa54f66a22821e3f 100644 (file)
@@ -15,6 +15,7 @@
 using System;
 using System.Collections.Generic;
 using System.Text;
+using Mono.CompilerServices.SymbolWriter;
 
 #if NET_2_1
 using XmlElement = System.Object;
@@ -361,8 +362,13 @@ namespace Mono.CSharp
                                CheckAbstractAndExtern (block != null);
                                CheckProtectedModifier ();
 
-                               if (block != null && block.IsIterator)
-                                       Iterator.CreateIterator (this, Parent.PartialContainer, ModFlags);
+                               if (block != null) {
+                                       if (block.IsIterator)
+                                               Iterator.CreateIterator (this, Parent.PartialContainer, ModFlags);
+
+                                       if (Compiler.Settings.WriteMetadataOnly)
+                                               block = null;
+                               }
 
                                return null;
                        }
@@ -686,6 +692,15 @@ namespace Mono.CSharp
                                Set.UpdateName (this);
                }
 
+               public override void WriteDebugSymbol (MonoSymbolFile file)
+               {
+                       if (get != null)
+                               get.WriteDebugSymbol (file);
+
+                       if (set != null)
+                               set.WriteDebugSymbol (file);
+               }
+
                //
                //   Represents header string for documentation comment.
                //
@@ -896,7 +911,7 @@ namespace Mono.CSharp
 
                        public override void Emit (TypeDefinition parent)
                        {
-                               if ((method.ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN)) == 0) {
+                               if ((method.ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN)) == 0 && !Compiler.Settings.WriteMetadataOnly) {
                                        block = new ToplevelBlock (Compiler, ParameterInfo, Location) {
                                                IsCompilerGenerated = true
                                        };
@@ -928,11 +943,10 @@ namespace Mono.CSharp
 
                                var cond = new BooleanExpression (new Binary (Binary.Operator.Inequality,
                                        new Cast (new TypeExpression (Module.Compiler.BuiltinTypes.Object, Location), new LocalVariableReference (obj1, Location), Location),
-                                       new Cast (new TypeExpression (Module.Compiler.BuiltinTypes.Object, Location), new LocalVariableReference (obj2, Location), Location),
-                                       Location));
+                                       new Cast (new TypeExpression (Module.Compiler.BuiltinTypes.Object, Location), new LocalVariableReference (obj2, Location), Location)));
 
                                var body = new ExplicitBlock (block, Location, Location);
-                               block.AddStatement (new Do (body, cond, Location));
+                               block.AddStatement (new Do (body, cond, Location, Location));
 
                                body.AddStatement (new StatementExpression (
                                        new SimpleAssign (new LocalVariableReference (obj2, Location), new LocalVariableReference (obj1, Location))));
@@ -1184,6 +1198,9 @@ namespace Mono.CSharp
                                if (!method_data.Define (parent.PartialContainer, method.GetFullName (MemberName)))
                                        return null;
 
+                               if (Compiler.Settings.WriteMetadataOnly)
+                                       block = null;
+
                                MethodBuilder mb = method_data.MethodBuilder;
 
                                Spec = new MethodSpec (MemberKind.Method, parent.PartialContainer.Definition, this, ReturnType, mb, ParameterInfo, method.ModFlags);
@@ -1339,6 +1356,12 @@ namespace Mono.CSharp
                        base.Emit ();
                }
 
+               public override void WriteDebugSymbol (MonoSymbolFile file)
+               {
+                       add.WriteDebugSymbol (file);
+                       remove.WriteDebugSymbol (file);
+               }
+
                //
                //   Represents header string for documentation comment.
                //
@@ -1424,7 +1447,14 @@ namespace Mono.CSharp
 
                        public override MethodBuilder Define (TypeContainer parent)
                        {
-                               parameters.Resolve (this);
+                               // Disable reporting, parameters are resolved twice
+                               Report.DisableReporting ();
+                               try {
+                                       parameters.Resolve (this);
+                               } finally {
+                                       Report.EnableReporting ();
+                               }
+
                                return base.Define (parent);
                        }