Merge pull request #4710 from Unity-Technologies/additional-config-checks
[mono.git] / mcs / mcs / method.cs
index 8ac79aeec605dc83ea4637349600bc419193fa4f..c2b993564e2b354b066ca651e60f816da3707d00 100644 (file)
@@ -21,7 +21,7 @@ using System.Linq;
 using Mono.CompilerServices.SymbolWriter;
 using System.Runtime.CompilerServices;
 
-#if NET_2_1
+#if MOBILE
 using XmlElement = System.Object;
 #else
 using System.Xml;
@@ -165,8 +165,9 @@ namespace Mono.CSharp {
                        return s + parameters.GetSignatureForDocumentation ();
                }
 
-               public virtual void PrepareEmit ()
+               public override void PrepareEmit ()
                {
+                       base.PrepareEmit ();
                        parameters.ResolveDefaultValues (this);
                }
 
@@ -443,6 +444,10 @@ namespace Mono.CSharp {
                        return ms;
                }
 
+#if DEBUG
+               int counter = 100000;
+#endif
+
                public MethodSpec MakeGenericMethod (IMemberContext context, params TypeSpec[] targs)
                {
                        if (targs == null)
@@ -464,6 +469,10 @@ namespace Mono.CSharp {
                        inflated.constraints = TypeParameterSpec.InflateConstraints (inflator, constraints ?? GenericDefinition.TypeParameters);
                        inflated.state |= StateFlags.PendingMakeMethod;
 
+#if DEBUG
+                       inflated.ID += counter;
+                       counter += 100000;
+#endif
                        //                      if (inflated.parent == null)
                        //                              inflated.parent = parent;
 
@@ -722,7 +731,12 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       if (type_expr != null)
+                       //
+                       // Optimization but it also covers cases where we cannot check
+                       // constraints because method is captured into generated class
+                       // and type parameters context is now different
+                       //
+                       if (type_expr != null && !IsCompilerGenerated)
                                ConstraintChecker.Check (this, member_type, type_expr.Location);
 
                        base.Emit ();
@@ -1766,8 +1780,12 @@ namespace Mono.CSharp {
                                // If we use a "this (...)" constructor initializer, then
                                // do not emit field initializers, they are initialized in the other constructor
                                //
-                               if (!(Initializer is ConstructorThisInitializer))
+                               if (!(Initializer is ConstructorThisInitializer)) {
+                                       var errors = Compiler.Report.Errors;
                                        Parent.PartialContainer.ResolveFieldInitializers (bc);
+                                       if (errors != Compiler.Report.Errors)
+                                               return;
+                               }
 
                                if (!IsStatic) {
                                        if (Initializer == null && Parent.PartialContainer.Kind == MemberKind.Class) {
@@ -1857,6 +1875,7 @@ namespace Mono.CSharp {
                        if (debug_builder == null)
                                return;
 
+#if !FULL_AOT_RUNTIME
                        var token = ConstructorBuilder.GetToken ();
                        int t = token.Token;
 #if STATIC
@@ -1865,6 +1884,7 @@ namespace Mono.CSharp {
 #endif
 
                        debug_builder.DefineMethod (file, t);
+#endif
                }
 
                #region IMethodData Members
@@ -2187,6 +2207,7 @@ namespace Mono.CSharp {
                        if (debug_builder == null)
                                return;
 
+#if !FULL_AOT_RUNTIME
                        var token = builder.GetToken ();
                        int t = token.Token;
 #if STATIC
@@ -2195,6 +2216,7 @@ namespace Mono.CSharp {
 #endif
 
                        debug_builder.DefineMethod (file, t);
+#endif
                }
        }