[657623] Fix incorrect logic in value type parameter `is' check
authorMarek Safar <marek.safar@gmail.com>
Tue, 14 Dec 2010 10:58:05 +0000 (10:58 +0000)
committerMarek Safar <marek.safar@gmail.com>
Tue, 14 Dec 2010 11:26:52 +0000 (11:26 +0000)
mcs/mcs/expression.cs
mcs/tests/gtest-415.cs [new file with mode: 0644]

index 742e11503bdd6ee81f7617b6023bc578a8941ff6..9289f179c51eccb75d8a3b37978997964367973c 100644 (file)
@@ -1442,7 +1442,7 @@ namespace Mono.CSharp
                        }
 
                        if (TypeManager.IsGenericParameter (expr.Type)) {
-                               if (t.IsValueType && expr.Type == t)
+                               if (t.IsValueType && expr.Type == d)
                                        return CreateConstantResult (ec, true);
 
                                expr = new BoxedCast (expr, d);
diff --git a/mcs/tests/gtest-415.cs b/mcs/tests/gtest-415.cs
new file mode 100644 (file)
index 0000000..c8f32bc
--- /dev/null
@@ -0,0 +1,20 @@
+using System;
+
+class Foo
+{
+       static int Main ()
+       {
+               if (Bar (1))
+                       return 1;
+
+               if (!Bar (IntPtr.Zero))
+                       return 2;
+
+               return 0;
+       }
+
+       static bool Bar<T> (T val) where T : struct
+       {
+               return val is IntPtr;
+       }
+}