Skip to content

Commit

Permalink
Merge pull request #68091 from sharwell/as-nullable
Browse files Browse the repository at this point in the history
Use AsNullable helper method where appropriate
  • Loading branch information
sharwell committed May 4, 2023
2 parents 2f32425 + ae567da commit 806dba8
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/Workspaces/Core/Portable/Workspace/Solution/Document.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,9 @@ public bool SupportsSemanticModel
// if we have a cached result task use it
if (_syntaxTreeResultTask != null)
{
// _syntaxTreeResultTask is a Task<SyntaxTree> so the ! operator here isn't suppressing a possible null ref, but rather allowing the
// conversion from Task<SyntaxTree> to Task<SyntaxTree?> since Task itself isn't properly variant.
return _syntaxTreeResultTask!;
return _syntaxTreeResultTask.AsNullable();
}

// check to see if we already have the tree before actually going async
if (TryGetSyntaxTree(out var tree))
{
Expand All @@ -184,15 +183,11 @@ public bool SupportsSemanticModel
// its okay to cache the task and hold onto the SyntaxTree, because the DocumentState already keeps the SyntaxTree alive.
Interlocked.CompareExchange(ref _syntaxTreeResultTask, Task.FromResult(tree), null);

// _syntaxTreeResultTask is a Task<SyntaxTree> so the ! operator here isn't suppressing a possible null ref, but rather allowing the
// conversion from Task<SyntaxTree> to Task<SyntaxTree?> since Task itself isn't properly variant.
return _syntaxTreeResultTask!;
return _syntaxTreeResultTask.AsNullable();
}

// do it async for real.
// GetSyntaxTreeAsync returns a Task<SyntaxTree> so the ! operator here isn't suppressing a possible null ref, but rather allowing the
// conversion from Task<SyntaxTree> to Task<SyntaxTree?> since Task itself isn't properly variant.
return DocumentState.GetSyntaxTreeAsync(cancellationToken).AsTask()!;
return DocumentState.GetSyntaxTreeAsync(cancellationToken).AsTask().AsNullable();
}

internal SyntaxTree? GetSyntaxTreeSynchronously(CancellationToken cancellationToken)
Expand Down

0 comments on commit 806dba8

Please sign in to comment.