Skip to content

Commit

Permalink
IsLastTokenOfNode should not set its out parameter when it fails
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi committed Apr 20, 2020
1 parent c7c78a9 commit edc9680
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable

using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
Expand All @@ -18,10 +20,17 @@ internal static partial class SyntaxTokenExtensions
public static bool IsLastTokenOfNode<T>(this SyntaxToken token) where T : SyntaxNode
=> token.IsLastTokenOfNode<T>(out _);

public static bool IsLastTokenOfNode<T>(this SyntaxToken token, [NotNullWhen(true)] out T node) where T : SyntaxNode
public static bool IsLastTokenOfNode<T>(this SyntaxToken token, [NotNullWhen(true)] out T? node) where T : SyntaxNode
{
node = token.GetAncestor<T>();
return node != null && token == node.GetLastToken(includeZeroWidth: true);
var ancestor = token.GetAncestor<T>();
if (ancestor == null || token != ancestor.GetLastToken(includeZeroWidth: true))
{
node = null;
return false;
}

node = ancestor;
return true;
}

public static bool IsKindOrHasMatchingText(this SyntaxToken token, SyntaxKind kind)
Expand Down

0 comments on commit edc9680

Please sign in to comment.