Skip to content

Commit

Permalink
Merge pull request dotnet/corefx#16150 from JonHanna/pointer_types_ty…
Browse files Browse the repository at this point in the history
…pe_equal_is

Test and optimise TypeEqual and TypeIs behaviour for pointer types.

Commit migrated from dotnet/corefx@11c6841
  • Loading branch information
VSadov authored Feb 19, 2017
2 parents 95b5156 + 6b1f56a commit 492d736
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private static AnalyzeTypeIsResult AnalyzeTypeIs(Expression operand, Type testTy
return testType == typeof(void) ? AnalyzeTypeIsResult.KnownTrue : AnalyzeTypeIsResult.KnownFalse;
}

if (testType == typeof(void))
if (testType == typeof(void) || testType.IsPointer)
{
return AnalyzeTypeIsResult.KnownFalse;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ internal Expression ReduceTypeEqual()
{
Type cType = Expression.Type;

if (cType.GetTypeInfo().IsValueType)
if (cType.GetTypeInfo().IsValueType || TypeOperand.IsPointer)
{
if (cType.IsNullableType())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ public void TypeByRef()
Assert.Throws<ArgumentException>("type", () => Expression.TypeEqual(exp, byRef));
}

[Theory, ClassData(typeof(CompilationTypes))]
public void TypePointer(bool useInterpreter)
{
Expression exp = Expression.Constant(0);
Type pointer = typeof(int*);
var test = Expression.TypeEqual(exp, pointer);
var lambda = Expression.Lambda<Func<bool>>(test);
var func = lambda.Compile(useInterpreter);
Assert.False(func());
}

[Fact]
public void UnreadableExpression()
{
Expand Down
11 changes: 11 additions & 0 deletions src/libraries/System.Linq.Expressions/tests/TypeBinary/TypeIs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ public void TypeByRef()
Assert.Throws<ArgumentException>("type", () => Expression.TypeIs(exp, byRef));
}

[Theory, ClassData(typeof(CompilationTypes))]
public void TypePointer(bool useInterpreter)
{
Expression exp = Expression.Constant(0);
Type pointer = typeof(int*);
var test = Expression.TypeIs(exp, pointer);
var lambda = Expression.Lambda<Func<bool>>(test);
var func = lambda.Compile(useInterpreter);
Assert.False(func());
}

[Fact]
public void UnreadableExpression()
{
Expand Down

0 comments on commit 492d736

Please sign in to comment.