Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

CSHARP-542: normalized a vb expression related to nullable comparisons.

  • Loading branch information...
commit 34b7e877bbec6c31fd8bd0c341fcd243fa543520 1 parent f81e9d9
@craiggwilson craiggwilson authored rstam committed
View
32 Driver/Linq/Expressions/ExpressionNormalizer.cs
@@ -61,6 +61,27 @@ protected override Expression VisitBinary(BinaryExpression node)
{
node = EnsureConstantIsOnRight(node);
+ if (node.Type == typeof(Nullable<bool>))
+ {
+ switch (node.NodeType)
+ {
+ case ExpressionType.Equal:
+ case ExpressionType.GreaterThan:
+ case ExpressionType.GreaterThanOrEqual:
+ case ExpressionType.LessThan:
+ case ExpressionType.LessThanOrEqual:
+ case ExpressionType.NotEqual:
+ node = Expression.MakeBinary(
+ node.NodeType,
+ node.Left,
+ node.Right,
+ false,
+ null,
+ null);
+ break;
+ }
+ }
+
Expression result = null;
if (node.Left.NodeType == ExpressionType.Call && node.Right.NodeType == ExpressionType.Constant)
{
@@ -118,16 +139,19 @@ protected override Expression VisitBinary(BinaryExpression node)
/// <returns>The UnaryExpression (possibly modified).</returns>
protected override Expression VisitUnary(UnaryExpression node)
{
- if (node.NodeType == ExpressionType.Convert || node.NodeType == ExpressionType.ConvertChecked)
+ var newNode = base.VisitUnary(node);
+
+ if (newNode.NodeType == ExpressionType.Convert || newNode.NodeType == ExpressionType.ConvertChecked)
{
- if (node.Type.IsAssignableFrom(node.Operand.Type))
+ var newUnaryNode = (UnaryExpression)newNode;
+ if (newUnaryNode.Type.IsAssignableFrom(newUnaryNode.Operand.Type))
{
// ignore the unnecessary conversion added by VB
- return Visit(node.Operand);
+ newNode = newUnaryNode.Operand;
}
}
- return base.VisitUnary(node);
+ return newNode;
}
private BinaryExpression EnsureConstantIsOnRight(BinaryExpression node)
View
1  DriverUnitTestsVB/DriverUnitTestsVB.vbproj
@@ -67,6 +67,7 @@
<Import Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="Jira\CSharp542.vb" />
<Compile Include="Linq\MongoQueryableTests.vb" />
<Compile Include="Linq\MongoQueryProviderTests.vb" />
<Compile Include="Linq\SelectDictionaryTests.vb" />
View
52 DriverUnitTestsVB/Jira/CSharp542.vb
@@ -0,0 +1,52 @@
+' Copyright 2010-2012 10gen Inc.
+'*
+'* Licensed under the Apache License, Version 2.0 (the "License");
+'* you may not use this file except in compliance with the License.
+'* You may obtain a copy of the License at
+'*
+'* http://www.apache.org/licenses/LICENSE-2.0
+'*
+'* Unless required by applicable law or agreed to in writing, software
+'* distributed under the License is distributed on an "AS IS" BASIS,
+'* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+'* See the License for the specific language governing permissions and
+'* limitations under the License.
+'
+
+
+Imports System.Collections.Generic
+Imports System.Linq
+Imports System.Text
+Imports NUnit.Framework
+
+Imports MongoDB.Bson
+Imports MongoDB.Bson.Serialization.Attributes
+Imports MongoDB.Driver
+Imports MongoDB.Driver.Linq
+
+Namespace MongoDB.DriverUnitTests.Jira
+
+ <TestFixture()>
+ Public Class CSharp542
+
+ Public Class Test
+ Public Id As ObjectId
+
+ Public MyNullableInt As Nullable(Of Integer)
+ End Class
+
+ <Test()>
+ Public Sub TestNullableComparison()
+
+ Dim server = MongoServer.Create()
+ Dim db = server.GetDatabase("test")
+ Dim col = db.GetCollection(Of Test)("foos")
+
+ Dim query = col.AsQueryable.Where(Function(p) p.MyNullableInt = 3)
+
+ Dim list = query.ToList()
+
+ End Sub
+ End Class
+
+End Namespace
Please sign in to comment.
Something went wrong with that request. Please try again.