提交 e4ebfd07 编写于 作者: J Jason Malinowski

Add some handling around nullability and error types

When we're inferring around error types, we won't add ?s for now because
they're more likely to be classes than structs, and we don't know yet
exactly where the resulting syntax will get put.

https://github.com/dotnet/roslyn/issues/37852 will track a fancier fix
to this.
上级 545d7b48
......@@ -157,6 +157,17 @@ public async Task TestCoalesce4()
@"var q = [|Goo()|] ?? string.Empty;", "global::System.String?", TestMode.Node);
}
[Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
public async Task TestCoalesceWithErrorType()
{
// We could be smart and infer this as an ErrorType?, but in the #nullable disable case we don't know if this is intended to be
// a struct (where the question mark is legal) or a class (where it isn't). We'll thus avoid sticking question marks in this case.
// https://github.com/dotnet/roslyn/issues/37852 tracks fixing this is a much fancier way.
await TestInMethodAsync(
@"ErrorType s;
var q = [|Goo()|] ?? s;", "ErrorType", TestMode.Node);
}
[Theory, CombinatorialData, Trait(Traits.Feature, Traits.Features.TypeInferenceService)]
public async Task TestBinaryExpression1(TestMode mode)
{
......
......@@ -1088,7 +1088,14 @@ private IEnumerable<TypeInferenceInfo> InferTypeInCatchFilterClause(CatchFilterC
static ITypeSymbol MakeNullable(ITypeSymbol symbol, Compilation compilation)
{
if (symbol.IsValueType)
if (symbol.IsErrorType())
{
// We could be smart and infer this as an ErrorType?, but in the #nullable disable case we don't know if this is intended to be
// a struct (where the question mark is legal) or a class (where it isn't). We'll thus avoid sticking question marks in this case.
// https://github.com/dotnet/roslyn/issues/37852 tracks fixing this is a much fancier way.
return symbol;
}
else if (symbol.IsValueType)
{
return compilation.GetSpecialType(SpecialType.System_Nullable_T).Construct(symbol.WithoutNullability());
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册