diff --git a/src/System.Linq.Expressions/src/System/Linq/Expressions/Common/ConstantCheck.cs b/src/System.Linq.Expressions/src/System/Linq/Expressions/Common/ConstantCheck.cs index d954202c440d..ab64d657cd1d 100644 --- a/src/System.Linq.Expressions/src/System/Linq/Expressions/Common/ConstantCheck.cs +++ b/src/System.Linq.Expressions/src/System/Linq/Expressions/Common/ConstantCheck.cs @@ -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; } diff --git a/src/System.Linq.Expressions/src/System/Linq/Expressions/TypeBinaryExpression.cs b/src/System.Linq.Expressions/src/System/Linq/Expressions/TypeBinaryExpression.cs index cbf859c0b329..dd2281340007 100644 --- a/src/System.Linq.Expressions/src/System/Linq/Expressions/TypeBinaryExpression.cs +++ b/src/System.Linq.Expressions/src/System/Linq/Expressions/TypeBinaryExpression.cs @@ -52,7 +52,7 @@ internal Expression ReduceTypeEqual() { Type cType = Expression.Type; - if (cType.GetTypeInfo().IsValueType) + if (cType.GetTypeInfo().IsValueType || TypeOperand.IsPointer) { if (cType.IsNullableType()) { diff --git a/src/System.Linq.Expressions/tests/TypeBinary/TypeEqual.cs b/src/System.Linq.Expressions/tests/TypeBinary/TypeEqual.cs index f4b1cb462a03..4139b9a3e259 100644 --- a/src/System.Linq.Expressions/tests/TypeBinary/TypeEqual.cs +++ b/src/System.Linq.Expressions/tests/TypeBinary/TypeEqual.cs @@ -29,6 +29,17 @@ public void TypeByRef() Assert.Throws("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>(test); + var func = lambda.Compile(useInterpreter); + Assert.False(func()); + } + [Fact] public void UnreadableExpression() { diff --git a/src/System.Linq.Expressions/tests/TypeBinary/TypeIs.cs b/src/System.Linq.Expressions/tests/TypeBinary/TypeIs.cs index 5cc40f04e7c9..e6141f138263 100644 --- a/src/System.Linq.Expressions/tests/TypeBinary/TypeIs.cs +++ b/src/System.Linq.Expressions/tests/TypeBinary/TypeIs.cs @@ -29,6 +29,17 @@ public void TypeByRef() Assert.Throws("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>(test); + var func = lambda.Compile(useInterpreter); + Assert.False(func()); + } + [Fact] public void UnreadableExpression() {