提交 9360caf3 编写于 作者: J Jason Malinowski

Update the type inferrer now that we can pass nullability when constructing types

上级 54346fe1
......@@ -1623,7 +1623,7 @@ public async Task TestForEach()
await TestInMethodAsync(@"foreach (int v in [|Goo()|]) { }", "global::System.Collections.Generic.IEnumerable<global::System.Int32>");
}
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/36046"), Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/37309"), Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
public async Task TestForEachNullableElements()
{
await TestInMethodAsync(
......@@ -2508,7 +2508,7 @@ void M()
await TestAsync(text, "global::System.Threading.Tasks.Task<global::System.Int32>");
}
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/36046"), Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
[Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
public async Task TestAwaitTaskOfTNullableValue()
{
var text =
......@@ -3031,7 +3031,7 @@ static void Main(string[] args)
await TestAsync(text, "global::Program", testNode: false);
}
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/36046"), Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/37310"), Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
public async Task TestInferringThroughGenericFunctionWithNullableReturn()
{
var text =
......
......@@ -618,7 +618,7 @@ private IMethodSymbol Instantiate(IMethodSymbol method, IList<ITypeSymbol> invoc
return method;
}
// TODO: pass nullability once https://github.com/dotnet/roslyn/issues/36046 is fixed
// TODO: pass nullability once https://github.com/dotnet/roslyn/issues/37310 is fixed
var typeArguments = method.ConstructedFrom.TypeParameters
.Select(tp => (bestMap.GetValueOrDefault(tp) ?? tp).WithoutNullability()).ToArray();
return method.ConstructedFrom.Construct(typeArguments);
......@@ -1219,8 +1219,7 @@ private IEnumerable<TypeInferenceInfo> InferTypeInForEachStatement(ForEachStatem
var type = this.Compilation.GetSpecialType(SpecialType.System_Collections_Generic_IEnumerable_T);
// TODO: pass the nullability to Construct once https://github.com/dotnet/roslyn/issues/36046 is fixed
return variableTypes.Select(v => new TypeInferenceInfo(type.Construct(v.InferredType.WithoutNullability())));
return variableTypes.Select(v => new TypeInferenceInfo(type.ConstructWithNullability(v.InferredType)));
}
private IEnumerable<TypeInferenceInfo> InferTypeInForStatement(ForStatementSyntax forStatement, ExpressionSyntax expressionOpt = null, SyntaxToken? previousToken = null)
......@@ -1702,8 +1701,7 @@ private IEnumerable<TypeInferenceInfo> InferTypeInNameColon(NameColonSyntax name
this.Compilation.ObjectType;
}
// TODO: pass the nullability to Construct once https://github.com/dotnet/roslyn/issues/36046 is fixed
return CreateResult(ienumerableType.Construct(typeArg.WithoutNullability()));
return CreateResult(ienumerableType.ConstructWithNullability(typeArg));
}
}
}
......@@ -1882,8 +1880,7 @@ private IEnumerable<TypeInferenceInfo> InferTypeInAwaitExpression(AwaitExpressio
return CreateResult(task);
}
// TODO: pass along nullability to Construct when https://github.com/dotnet/roslyn/issues/36046 is fixed.
return types.Select(t => t.InferredType.SpecialType == SpecialType.System_Void ? new TypeInferenceInfo(task) : new TypeInferenceInfo(taskOfT.Construct(t.InferredType.WithoutNullability())));
return types.Select(t => t.InferredType.SpecialType == SpecialType.System_Void ? new TypeInferenceInfo(task) : new TypeInferenceInfo(taskOfT.ConstructWithNullability(t.InferredType)));
}
private IEnumerable<TypeInferenceInfo> InferTypeInYieldStatement(YieldStatementSyntax yieldStatement, SyntaxToken? previousToken = null)
......
......@@ -26,8 +26,7 @@ internal class CodeGenerationConstructedNamedTypeSymbol : CodeGenerationAbstract
public override ImmutableArray<ITypeSymbol> TypeArguments => _typeArguments;
// TODO: implement this once INamedTypeSymbol.Construct is fixed in https://github.com/dotnet/roslyn/issues/36046
public override ImmutableArray<NullableAnnotation> TypeArgumentNullableAnnotations => _typeArguments.SelectAsArray(t => NullableAnnotation.NotAnnotated);
public override ImmutableArray<NullableAnnotation> TypeArgumentNullableAnnotations => _typeArguments.SelectAsArray(t => t.GetNullability());
public override int Arity => _constructedFrom.Arity;
......
......@@ -599,8 +599,7 @@ private static bool IsOverridable(ISymbol member, INamedTypeSymbol containingTyp
public static INamedTypeSymbol TryConstruct(this INamedTypeSymbol type, ITypeSymbol[] typeArguments)
{
// TODO: pass along nullability once https://github.com/dotnet/roslyn/issues/36046 is fixed
return typeArguments.Length > 0 ? type.Construct(typeArguments.Select(t => t.WithoutNullability()).ToArray()) : type;
return typeArguments.Length > 0 ? type.ConstructWithNullability(typeArguments) : type;
}
}
}
......@@ -26,7 +26,7 @@ public ITypeSymbol CreatePointerTypeSymbol(ITypeSymbol pointedAtType)
public ITypeSymbol Construct(INamedTypeSymbol namedType, ITypeSymbol[] typeArguments)
{
return namedType.Construct(typeArguments);
return namedType.ConstructWithNullability(typeArguments);
}
}
}
......
......@@ -87,8 +87,7 @@ public override ITypeSymbol VisitNamedType(INamedTypeSymbol symbol)
return symbol;
}
// TODO: pass nullability to the substituted arguments once https://github.com/dotnet/roslyn/issues/36046 is fixed
return _typeGenerator.Construct(symbol.OriginalDefinition, substitutedArguments.Select(t => t.WithoutNullability()).ToArray()).WithNullability(symbol.GetNullability());
return _typeGenerator.Construct(symbol.OriginalDefinition, substitutedArguments.ToArray()).WithNullability(symbol.GetNullability());
}
public override ITypeSymbol VisitArrayType(IArrayTypeSymbol symbol)
......
......@@ -317,7 +317,7 @@ private static bool ImplementsIEquatable(ITypeSymbol memberType, INamedTypeSymbo
{
if (iequatableType != null)
{
// TODO: pass the nullability to Construct once https://github.com/dotnet/roslyn/issues/36046 is fixed
// It's correct to throw out nullability here -- if you have a field of type Foo? and it implements IEquatable, it's still implementing IEquatable<Foo>.
var constructed = iequatableType.Construct(memberType.WithoutNullability());
return memberType.AllInterfaces.Contains(constructed);
}
......
......@@ -110,5 +110,10 @@ public static ITypeSymbol GetTypeWithAnnotatedNullability(this IEventSymbol even
public static ITypeSymbol GetTypeWithAnnotatedNullability(this ILocalSymbol localSymbol)
=> localSymbol.Type.WithNullability(localSymbol.NullableAnnotation);
public static INamedTypeSymbol ConstructWithNullability(this INamedTypeSymbol typeSymbol, params ITypeSymbol[] typeArguments)
{
return typeSymbol.Construct(typeArguments.SelectAsArray(t => t.WithoutNullability()), typeArguments.SelectAsArray(t => t.GetNullability()));
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册