Skip to content

Commit

Permalink
FunctionCallBinder promotes arguments without checking return type (#…
Browse files Browse the repository at this point in the history
…2257)

* FunctionCallBinder promotes arguments without checking return type
  • Loading branch information
JBBianchi authored Dec 1, 2021
1 parent 5f9cd57 commit 7bce571
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ private QueryNode BindAsUriFunction(FunctionCallToken functionCallToken, List<Qu

string canonicalName = nameSignature.Key;
FunctionSignatureWithReturnType signature = nameSignature.Value;
if (signature.ReturnType != null)
if (signature != null)
{
TypePromoteArguments(signature, argumentNodes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,8 @@ public void NullValueInCanonicalFunction()
var result = ParseFilter("day(null)", HardCodedTestModel.TestModel, HardCodedTestModel.GetPaintingType());

var typeReference = result.Expression.ShouldBeSingleValueFunctionCallQueryNode("day")
.Parameters.Single().ShouldBeConstantQueryNode<object>(null).TypeReference;
.Parameters.Single().ShouldBeConvertQueryNode(EdmPrimitiveTypeKind.DateTimeOffset)
.Source.ShouldBeConstantQueryNode<object>(null).TypeReference;
Assert.Null(typeReference);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ public void OpenPropertyInSingleParameterBuiltInFunction()
var orderBy = ParseOrderBy("day(Genre)", HardCodedTestModel.TestModel, HardCodedTestModel.GetPaintingType());

var functionNode = orderBy.Expression.ShouldBeSingleValueFunctionCallQueryNode("day");
functionNode.Parameters.Single().ShouldBeSingleValueOpenPropertyAccessQueryNode("Genre");
functionNode.Parameters.Single().ShouldBeConvertQueryNode(EdmPrimitiveTypeKind.DateTimeOffset)
.Source.ShouldBeSingleValueOpenPropertyAccessQueryNode("Genre");
Assert.Null(functionNode.TypeReference);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public void BindFunctionForNullArgumentType()
var arguments = new List<QueryToken>() { new LiteralToken("ignored") };
var token = new FunctionCallToken("year", arguments);
var result = functionCallBinder.BindFunctionCall(token);
Assert.Null(result.ShouldBeSingleValueFunctionCallQueryNode("year").Parameters.Single().ShouldBeConstantQueryNode<object>(null).TypeReference);
var argumentNode = result.ShouldBeSingleValueFunctionCallQueryNode("year").Parameters.Single();
Assert.Null(argumentNode.ShouldBeConvertQueryNode(EdmPrimitiveTypeKind.DateTimeOffset).Source.ShouldBeConstantQueryNode<object>(null).TypeReference);
}

[Fact]
Expand All @@ -61,10 +62,10 @@ public void BindFunctionAllNullArgumentTypes()
var arguments = new List<QueryToken>() { new LiteralToken("ignored"), new LiteralToken("ignored") };
var token = new FunctionCallToken("substring", arguments);
var result = functionCallBinder.BindFunctionCall(token);
var functionCallNode = result.ShouldBeSingleValueFunctionCallQueryNode("substring");
Assert.Equal(2, functionCallNode.Parameters.Count());
Assert.Null(functionCallNode.Parameters.First().ShouldBeConstantQueryNode<object>(null).TypeReference);
Assert.Null(functionCallNode.Parameters.Last().ShouldBeConstantQueryNode<object>(null).TypeReference);
var parameters = result.ShouldBeSingleValueFunctionCallQueryNode("substring").Parameters;
Assert.Equal(2, parameters.Count());
Assert.Null(parameters.First().ShouldBeConvertQueryNode(EdmPrimitiveTypeKind.String).Source.ShouldBeConstantQueryNode<object>(null).TypeReference);
Assert.Null(parameters.Last().ShouldBeConvertQueryNode(EdmPrimitiveTypeKind.Int32).Source.ShouldBeConstantQueryNode<object>(null).TypeReference);
}

[Fact]
Expand Down

0 comments on commit 7bce571

Please sign in to comment.