Fixed nullability rewrites with parameters and return types

This commit is contained in:
Koen Bekkenutte
2021-10-18 23:40:43 +08:00
parent 8ccb73d424
commit 8c611b9fd4
11 changed files with 184 additions and 25 deletions
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable
{
public static class Foo_C_NextFoo
{
public static System.Linq.Expressions.Expression<System.Func<List<object> ,List<int?>, List<object>>> Expression =>
(List<object> input,List<int?> nullablePrimitiveArgument) => input;
}
}
@@ -9,7 +9,7 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_EntityExtensions_GetFirstRelatedIgnoreNulls
{
public static System.Linq.Expressions.Expression<System.Func<Entity, global::Foo.EntityExtensions.Entity>> Expression =>
public static System.Linq.Expressions.Expression<System.Func<Entity, Entity>> Expression =>
(Entity entity) => entity.RelatedEntities[0];
}
}
@@ -9,7 +9,7 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_EntityExtensions_GetFirstRelatedIgnoreNulls
{
public static System.Linq.Expressions.Expression<System.Func<Entity, global::Foo.EntityExtensions.Entity>> Expression =>
public static System.Linq.Expressions.Expression<System.Func<Entity, Entity>> Expression =>
(Entity entity) => entity != null ? (entity.RelatedEntities != null ? (entity.RelatedEntities[0]) : null) : null;
}
}
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable
{
public static class Foo_C_NullableReferenceType
{
public static System.Linq.Expressions.Expression<System.Func<object, string>> Expression =>
(object input) => (string)input;
}
}
@@ -8,7 +8,7 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_C_NextFoo
{
public static System.Linq.Expressions.Expression<System.Func<object? ,int?, object>> Expression =>
(object? unusedArgument,int? nullablePrimitiveArgument) => null;
public static System.Linq.Expressions.Expression<System.Func<object ,int?, object>> Expression =>
(object unusedArgument,int? nullablePrimitiveArgument) => null;
}
}
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable
{
public static class Foo_C_NullableValueType
{
public static System.Linq.Expressions.Expression<System.Func<object, int?>> Expression =>
(object input) => (int?)input;
}
}
@@ -487,6 +487,88 @@ namespace Foo {
return Verifier.Verify(result.GeneratedTrees[0].ToString());
}
[Fact]
public Task GenericNullableReferenceTypesAreBeingEliminated()
{
var compilation = CreateCompilation(@"
using System;
using System.Collections.Generic;
using System.Linq;
using EntityFrameworkCore.Projectables;
#nullable enable
namespace Foo {
static class C {
[Projectable]
public static List<object?> NextFoo(this List<object?> input, List<int?> nullablePrimitiveArgument) => input;
}
}
");
var result = RunGenerator(compilation);
Assert.Empty(result.Diagnostics);
Assert.Single(result.GeneratedTrees);
return Verifier.Verify(result.GeneratedTrees[0].ToString());
}
[Fact]
public Task NullableReferenceTypeCastOperatorGetsEliminated()
{
var compilation = CreateCompilation(@"
using System;
using System.Collections.Generic;
using System.Linq;
using EntityFrameworkCore.Projectables;
#nullable enable
namespace Foo {
static class C {
[Projectable]
public static string? NullableReferenceType(object? input) => (string?)input;
}
}
");
var result = RunGenerator(compilation);
Assert.Empty(result.Diagnostics);
Assert.Single(result.GeneratedTrees);
return Verifier.Verify(result.GeneratedTrees[0].ToString());
}
[Fact]
public Task NullableValueCastOperatorsPersist()
{
var compilation = CreateCompilation(@"
using System;
using System.Collections.Generic;
using System.Linq;
using EntityFrameworkCore.Projectables;
#nullable enable
namespace Foo {
static class C {
[Projectable]
public static int? NullableValueType(object? input) => (int?)input;
}
}
");
var result = RunGenerator(compilation);
Assert.Empty(result.Diagnostics);
Assert.Single(result.GeneratedTrees);
return Verifier.Verify(result.GeneratedTrees[0].ToString());
}
[Fact]
public void NullableMemberBinding_WithoutSupport_IsBeingReported()
{