edit: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/IronPython/IronPythonTest/BindTest.cs;C1203609 File: BindTest.cs =================================================================== --- $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/IronPython/IronPythonTest/BindTest.cs;C1203609 (server) 2/23/2010 11:27 AM +++ Shelved Change: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/IronPython/IronPythonTest/BindTest.cs;TypeInferenceBugs @@ -978,6 +978,14 @@ public static PythonType M34(IList x, IList y) { return DynamicHelpers.GetPythonTypeFromType(typeof(T)); } + + public static PythonType M35(IList x) { + return DynamicHelpers.GetPythonTypeFromType(typeof(IList)); + } + + public static PythonType M35(T[] x) { + return DynamicHelpers.GetPythonTypeFromType(typeof(T[])); + } } public class SelfEnumerable : IEnumerable { @@ -1198,6 +1206,14 @@ public PythonType M34(IList x, IList y) { return DynamicHelpers.GetPythonTypeFromType(typeof(T)); } + + public static PythonType M35(IList x) { + return DynamicHelpers.GetPythonTypeFromType(typeof(IList)); + } + + public static PythonType M35(T[] x) { + return DynamicHelpers.GetPythonTypeFromType(typeof(T[])); + } } public class WithCompare { =================================================================== edit: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/IronPython/Tests/test_methodbinder1.py;C1300588 File: test_methodbinder1.py =================================================================== --- $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/IronPython/Tests/test_methodbinder1.py;C1300588 (server) 2/20/2010 10:30 AM +++ Shelved Change: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/IronPython/Tests/test_methodbinder1.py;TypeInferenceBugs @@ -875,7 +875,7 @@ def test_generic_type_inference(): from IronPythonTest import GenericTypeInference, GenericTypeInferenceInstance, SelfEnumerable from System import Array, Exception, ArgumentException - from System.Collections.Generic import IEnumerable, List + from System.Collections.Generic import IEnumerable, List, IList from System.Collections.Generic import Dictionary as Dict class UserGenericType(GenericTypeInferenceInstance): pass @@ -890,7 +890,6 @@ userTuple, userList, userDict = mytuple(), mylist(), mydict() objArray = System.Array[object]( (1,2,3) ) doubleArray = System.Array[float]( (1.0,2.0,3.0) ) - for target in [GenericTypeInference, GenericTypeInferenceInstance(), UserGenericType()]: tests = [ @@ -1061,8 +1060,14 @@ # public static PythonType M34(IList x, IList y) -> pytype(T) (target.M34, ((), [], ), object, True, None), + + # T[] and IList overloads: + (target.M35, (objArray, ), System.Array[object], False, None), ] - + + # TODO: more by-ref and arrays tests: + x = Array.Resize(Array.CreateInstance(int, 10), 20) + AreEqual(x.Length, 20) for method, args, res, kwArgs, excep in tests: generic_method_tester(method, args, res, kwArgs, excep) =================================================================== edit: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/IronPython/Tests/test_methoddispatch.py;C1459771 File: test_methoddispatch.py =================================================================== --- $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/IronPython/Tests/test_methoddispatch.py;C1459771 (server) 2/19/2010 4:51 PM +++ Shelved Change: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/IronPython/Tests/test_methoddispatch.py;TypeInferenceBugs @@ -1343,21 +1343,6 @@ AreEqual(res, 'abc') -# verify calling a generic method w/o args throws a reasonable exception -def test_array_badargs(): - import System - x = System.Array.CreateInstance(System.Byte, 1024) - try: - System.Array.Resize(x, 2048) - AssertUnreachable() - except TypeError: - pass - - System.Array.Resize[System.Byte](x, 2048) - - #TODO specify clearly which exception is appropriate here - AssertError(Exception, System.Collections.Generic.List) - # verify calls to explicit interface implementations def test_explicit(): x = ExplicitTest() =================================================================== edit: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/IronRuby.Tests/RubyTests.cs;C1602122 File: RubyTests.cs =================================================================== --- $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/IronRuby.Tests/RubyTests.cs;C1602122 (server) 2/17/2010 3:19 PM +++ Shelved Change: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/IronRuby.Tests/RubyTests.cs;TypeInferenceBugs @@ -469,6 +469,7 @@ ClrMethodEnumeration2, ClrIndexers1, ClrGenericMethods1, + ClrGenericParametersInference1, ClrOverloadSelection1, ClrOverloadSelection2, ClrNewSlot1, =================================================================== edit: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/ClrTests.cs;C1597865 File: ClrTests.cs =================================================================== --- $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/ClrTests.cs;C1597865 (server) 2/17/2010 3:18 PM +++ Shelved Change: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/ClrTests.cs;TypeInferenceBugs @@ -15,12 +15,14 @@ using System; using System.Collections; +using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using IronRuby.Builtins; using IronRuby.Runtime; +using Microsoft.Scripting.Hosting; using Microsoft.Scripting.Math; using Microsoft.Scripting.Runtime; using Microsoft.Scripting.Utils; @@ -58,6 +60,14 @@ void I.MethodOnI() { } void J.MethodOnJ() { } } + + public static class Extensions { + public static IEnumerable Select(this IEnumerable a, Func func) { + foreach (var item in a) { + yield return func(item); + } + } + } } namespace InteropTests.Namespaces2 { @@ -65,6 +75,8 @@ namespace N { public class D { } } + + } namespace IronRuby.Tests { @@ -544,6 +556,78 @@ # " ); + } + + public class Inference1 { + public int ByRef(ref T x) { + x = (T)(object)((int)(object)x + 1); + return 0; + } + + public int Array(T[] x) { + return 1; + } + + public int Multiple(IEnumerable source, Func selector) { + return 2; + } + + public int DeepShape(Dictionary, Dictionary> arg) { + return 3; + } + + public int Complex(ref Dictionary[], int>>, Func, B, C>>[] arg) { + return 4; + } + } + + public void ClrGenericParametersInference1() { + Context.ObjectClass.SetConstant("F", Context.GetClass(typeof(Func))); + Context.ObjectClass.SetConstant("SB", Context.GetClass(typeof(StrongBox))); + Context.ObjectClass.SetConstant("SBx", + new StrongBox[], int>>, Func, bool, double>>[]>() + ); + Context.ObjectClass.SetConstant("I", new Inference1()); + Context.ObjectClass.SetConstant("E", Context.GetClass(typeof(InteropTests.Generics1.Extensions))); + + TestOutput(@" +p I.Array(System::Array[Fixnum].new(3)) +p I.Multiple([1,2,3], F.new { |x| x.to_s }) +E.Select([1,2], F.new { |x| x.to_s + '!' }).each { |a| puts a } +E.Select([1,2], lambda { |x| x + 1 }).each { |a| puts a } +", @" +1 +2 +1! +2! +2 +3 +"); + + TestOutput(@" +p I.ByRef(2) +sb = SB.new(10) +p I.ByRef(sb), sb.Value +", @" +[0, 3] +0 +11 +"); + + TestOutput(@" +include System::Collections::Generic +p I.DeepShape(Dictionary[List[Fixnum], Dictionary[Fixnum, Fixnum]].new) rescue p $! +p I.DeepShape(Dictionary[Dictionary[Fixnum, System::String], Dictionary[Fixnum, Fixnum]].new) +", @" +# +3 +"); + + TestOutput(@" +p I.Complex(SBx) +", @" +4 +"); } #endregion =================================================================== edit: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Builtins/Proc.Meta.cs;C1107696 File: Proc.Meta.cs =================================================================== --- $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Builtins/Proc.Meta.cs;C1107696 (server) 2/23/2010 1:31 PM +++ Shelved Change: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Builtins/Proc.Meta.cs;TypeInferenceBugs @@ -19,26 +19,26 @@ using Microsoft.Scripting.Ast; #endif +using System; +using System.Reflection; using System.Dynamic; +using Microsoft.Scripting.Actions.Calls; using Microsoft.Scripting.Runtime; using Microsoft.Scripting.Utils; +using IronRuby.Compiler; using IronRuby.Runtime; using IronRuby.Runtime.Calls; -using AstUtils = Microsoft.Scripting.Ast.Utils; -using IronRuby.Compiler; -using System; -using System.Reflection; - namespace IronRuby.Builtins { using Ast = Expression; + using AstUtils = Microsoft.Scripting.Ast.Utils; public partial class Proc : IRubyDynamicMetaObjectProvider { public DynamicMetaObject/*!*/ GetMetaObject(Expression/*!*/ parameter) { return new Meta(parameter, BindingRestrictions.Empty, this); } - internal sealed class Meta : RubyMetaObject, IConvertibleMetaObject { + internal sealed class Meta : RubyMetaObject, IConvertibleMetaObject, IInferableInvokable { public override RubyContext/*!*/ Context { get { return Value.LocalScope.RubyContext; } } @@ -64,6 +64,18 @@ public override DynamicMetaObject/*!*/ BindInvoke(InvokeBinder/*!*/ binder, DynamicMetaObject/*!*/[]/*!*/ args) { return InteropBinder.Invoke.Bind(binder, this, args, Value.BuildInvoke); } + + #region IInvokableInferable Members + + InferenceResult IInferableInvokable.GetInferredType(Type delegateType, Type parameterType) { + // a block can be called with any number of parameters, so we don't need to restrict the result: + return new InferenceResult( + typeof(object), + BindingRestrictions.GetTypeRestriction(Expression, typeof(Proc)) + ); + } + + #endregion } } } ===================================================================