[interpreter] Relax check for forcing compilation for built-in structs
authorAlexander Köplinger <alex.koeplinger@outlook.com>
Wed, 21 Oct 2015 15:31:22 +0000 (17:31 +0200)
committerAlexander Köplinger <alex.koeplinger@outlook.com>
Wed, 21 Oct 2015 17:38:27 +0000 (19:38 +0200)
Method calls on structs like DateTime wouldn't work before,
even though we know we don't have self mutating structs in mscorlib.

Fixes part 2 of https://bugzilla.xamarin.com/show_bug.cgi?id=34334

mcs/class/System.Core/Test/System.Linq.Expressions/ExpressionTest_Call.cs
mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs

index 1edb2fa98eca01cbaac72ac28d970ab1a013a35d..3ef2df472ea22a00a778d53094460a673d7f0d07 100644 (file)
@@ -239,6 +239,17 @@ namespace MonoTests.System.Linq.Expressions {
                        return 42;
                }
 
+               [Test]
+               public void CallMethodOnDateTime ()
+               {
+                       var left = Expression.Call (Expression.Constant (DateTime.Now), typeof(DateTime).GetMethod ("AddDays"), Expression.Constant (-5.0));
+                       var right = Expression.Constant (DateTime.Today);
+                       var expr = Expression.GreaterThan (left, right);
+
+                       var eq = Expression.Lambda<Func<bool>> (expr).Compile ();
+                       Assert.IsFalse (eq ());
+               }
+
                [Test]
                [Category ("NotDotNet")] // http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=339351
                [ExpectedException (typeof (ArgumentException))]
@@ -382,7 +393,6 @@ namespace MonoTests.System.Linq.Expressions {
                }
 
                [Test]
-               [Category ("NotWorkingInterpreter")]
                public void Connect282702 ()
                {
                        var lambda = Expression.Lambda<Func<Func<int>>> (
index c58b0353f918ac4f8f165396b809f6013ec5815a..779d93a108622e138c1ffca53aeead00d33af366 100644 (file)
@@ -1278,7 +1278,7 @@ namespace Microsoft.Scripting.Interpreter {
             // also could be a mutable value type, Delegate.CreateDelegate and MethodInfo.Invoke both can't handle this, we
             // need to generate code.
             if (!CollectionUtils.TrueForAll(parameters, (p) => !p.ParameterType.IsByRef) ||
-                (!node.Method.IsStatic && node.Method.DeclaringType.IsValueType() && !node.Method.DeclaringType.IsPrimitive())) {
+                (!node.Method.IsStatic && node.Method.DeclaringType.IsValueType && node.Method.DeclaringType.Assembly != typeof (object).Assembly)) {
 #if MONO_INTERPRETER
                 throw new NotImplementedException ("Interpreter of ref types");
 #else