Skip to content

Commit

Permalink
Add null checks in AwaitExpressionInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
jcouv committed Dec 30, 2018
1 parent bff68d6 commit 6f98b20
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ public struct AwaitExpressionInfo : IEquatable<AwaitExpressionInfo>
{
private readonly AwaitableInfo _awaitableInfo;

public IMethodSymbol GetAwaiterMethod => _awaitableInfo.GetAwaiter;
public IMethodSymbol GetAwaiterMethod => _awaitableInfo?.GetAwaiter;

public IPropertySymbol IsCompletedProperty => _awaitableInfo.IsCompleted;
public IPropertySymbol IsCompletedProperty => _awaitableInfo?.IsCompleted;

public IMethodSymbol GetResultMethod => _awaitableInfo.GetResult;
public IMethodSymbol GetResultMethod => _awaitableInfo?.GetResult;

public bool IsDynamic => _awaitableInfo.IsDynamic;
public bool IsDynamic => _awaitableInfo?.IsDynamic == true;

internal AwaitExpressionInfo(AwaitableInfo awaitableInfo)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ public C(Task<int> t) {
Assert.Equal("System.Boolean System.Runtime.CompilerServices.TaskAwaiter<System.Int32>.IsCompleted { get; }", info.IsCompletedProperty.ToTestDisplayString());
}

[Fact]
[WorkItem(744146, "https://devdiv.visualstudio.com/DevDiv/_workitems/edit/744146")]
public void DefaultAwaitExpressionInfo()
{
AwaitExpressionInfo info = default;
Assert.Null(info.GetAwaiterMethod);
Assert.Null(info.GetResultMethod);
Assert.Null(info.IsCompletedProperty);
Assert.False(info.IsDynamic);
}

private AwaitExpressionInfo GetAwaitExpressionInfo(string text, out CSharpCompilation compilation, params DiagnosticDescription[] diagnostics)
{
var tree = Parse(text, options: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp5));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ End Module
AssertTheseDiagnostics(compilation, <expected></expected>)
End Sub

<Fact, WorkItem(744146, "https://devdiv.visualstudio.com/DevDiv/_workitems/edit/744146")>
Public Sub DefaultAwaitExpressionInfo()
Dim awaitInfo As AwaitExpressionInfo = Nothing

Assert.Null(awaitInfo.GetAwaiterMethod)
Assert.Null(awaitInfo.IsCompletedProperty)
Assert.Null(awaitInfo.GetResultMethod)
End Sub

<Fact()>
Public Sub AwaitableType01()
Dim source =
Expand Down

0 comments on commit 6f98b20

Please sign in to comment.