[runtime] Fail gracefully when method has conflicting attributes
[mono.git] / mcs / class / Microsoft.CSharp / Microsoft.CSharp.RuntimeBinder / CSharpGetIndexBinder.cs
index 2d2f30598771c0bf750700d92d2faedb01b07690..367cc22b70e1a63c50a50fc53a577e506f153cf3 100644 (file)
@@ -45,28 +45,7 @@ namespace Microsoft.CSharp.RuntimeBinder
                        this.callingContext = callingContext;
                        this.argumentInfo = argumentInfo.ToReadOnly ();
                }
-               
-               public IList<CSharpArgumentInfo> ArgumentInfo {
-                       get {
-                               return argumentInfo;
-                       }
-               }
-
-               public override bool Equals (object obj)
-               {
-                       var other = obj as CSharpGetIndexBinder;
-                       return other != null && other.callingContext == callingContext &&
-                               other.argumentInfo.SequenceEqual (argumentInfo);
-               }
-
-               public override int GetHashCode ()
-               {
-                       return Extensions.HashCode (
-                               callingContext.GetHashCode (),
-                               argumentInfo.GetHashCode (),
-                               GetType().GetHashCode ());
-               }
-               
+                       
                public override DynamicMetaObject FallbackGetIndex (DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject errorSuggestion)
                {
                        if (argumentInfo.Count != indexes.Length + 1) {
@@ -76,13 +55,17 @@ namespace Microsoft.CSharp.RuntimeBinder
                                return errorSuggestion;
                        }
 
-                       var expr = CSharpBinder.CreateCompilerExpression (argumentInfo [0], target);
-                       var args = CSharpBinder.CreateCompilerArguments (argumentInfo.Skip (1), indexes);
-                       expr = new Compiler.ElementAccess (expr, args);
-                       expr = new Compiler.Cast (new Compiler.TypeExpression (typeof (object), Compiler.Location.Null), expr); // TODO: ReturnType replace
+                       var ctx = DynamicContext.Create ();
+                       var expr = ctx.CreateCompilerExpression (argumentInfo [0], target);
+                       var args = ctx.CreateCompilerArguments (argumentInfo.Skip (1), indexes);
+                       expr = new Compiler.ElementAccess (expr, args, Compiler.Location.Null);
+                       expr = new Compiler.Cast (new Compiler.TypeExpression (ctx.ImportType (ReturnType), Compiler.Location.Null), expr, Compiler.Location.Null);
+
+                       var binder = new CSharpBinder (this, expr, errorSuggestion);
+                       binder.AddRestrictions (target);
+                       binder.AddRestrictions (indexes);
 
-                       var restrictions = CSharpBinder.CreateRestrictionsOnTarget (target).Merge (CSharpBinder.CreateRestrictionsOnTarget (indexes));
-                       return CSharpBinder.Bind (target, expr, callingContext, restrictions, errorSuggestion);
+                       return binder.Bind (ctx, callingContext);
                }
        }
 }