Skip to content

Conversation

@CyrusNajmabadi
Copy link
Member

Fixes #36117

The original code actually had a preprocessor-directive check. But the check was a little too narrow. This PR expands the check to handle the broader case. I also used this as an opportunity to unify a bunch of duplicate C#/VB code that was written prior to the great syntax unification.

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner June 2, 2019 20:22
}

public static bool SpansPreprocessorDirective(this IEnumerable<SyntaxToken> tokens)
{
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this moved to AbstractSyntaxFactsService so it could be shared between C# and VB instead of having it be duplicated.

}

public bool SpansPreprocessorDirective(IEnumerable<SyntaxNode> nodes)
=> nodes.SpansPreprocessorDirective();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this moved up to the base class.

Dim tokens = list.SelectMany(Function(n) n.DescendantTokens())

Return tokens.SpansPreprocessorDirective()
Return VisualBasicSyntaxFactsService.Instance.SpansPreprocessorDirective(list)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can now use common impl.

Next token

Return False
Return VisualBasicSyntaxFactsService.Instance.SpansPreprocessorDirective(tokens)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can now use common impl


Public Shadows Function SpansPreprocessorDirective(tokens As IEnumerable(Of SyntaxToken)) As Boolean
Return MyBase.SpansPreprocessorDirective(tokens)
End Function
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need these because VB doesn't automatically use base-class methods as 'interface impls'. So we just need the method here to satisfy the compiler, but we delegate to base to actually have the logic.

@CyrusNajmabadi
Copy link
Member Author

Tagging @jinujoseph @mavasani @dotnet/roslyn-ide . Easy bugfix PR. Can someone PTAL. Thanks!

function M() as integer
dim check as boolean = true
#if true
[||]if check
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this valid syntax for VB if statement?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what part? not having parens? If so, yes this is valid VB :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant:

If check Then
Return 3
End If

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah. the then is optional in VB. Automatic code cleanup adds it. but it's not necessary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you would still need the End If?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smacks-head. sorry. i get it now. will add hte other test as well :)

Copy link
Contributor

@mavasani mavasani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, we may want to fix unintentional syntax errors in the added VB test.

@gafter gafter added the Area-IDE label Jun 3, 2019
@mavasani mavasani merged commit 47d094b into dotnet:master Jun 3, 2019
@RayKoopa
Copy link

RayKoopa commented Jun 3, 2019

I know comments like this spam up the thread, but thanks for the extremely quick reaction and fix. :)

@CyrusNajmabadi
Copy link
Member Author

I know comments like this spam up the thread, but thanks for the extremely quick reaction and fix. :)

You're very welcome. Thank you for the great bug report.

@CyrusNajmabadi CyrusNajmabadi deleted the directiveCheck branch June 3, 2019 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"if statement can be simplified" does not respect preprocessor

4 participants