-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement parsing for Global Using Directive. #51426
Implement parsing for Global Using Directive. #51426
Conversation
break; | ||
|
||
case SyntaxKind.IdentifierToken: | ||
if (this.CurrentToken.ContextualKind != SyntaxKind.GlobalKeyword || this.PeekToken(1).Kind != SyntaxKind.UsingKeyword) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fwiw, i think tihs would be much clearer if hte if was flipped and the condition was just if (CurrentToken == Global && PeekToken(1) == Using)
. #WontFix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fwiw, i think tihs would be much clearer if hte if was flipped and the condition was just if (CurrentToken == Global && PeekToken(1) == Using).
I prefer to structure the code in this case section and in the previous section as close as possible.
In reply to: 581474923 [](ancestors = 581474923)
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
@@ -324,6 +325,7 @@ internal static LanguageVersion RequiredVersion(this MessageID feature) | |||
{ | |||
// C# preview features. | |||
case MessageID.IDS_FeatureMixedDeclarationsAndExpressionsInDeconstruction: | |||
case MessageID.IDS_FeatureUsingGlobal: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IDS_FeatureUsingGlobal [](start = 31, length = 22)
nit: "GlobalUsing" #Closed
if (staticToken != null) | ||
{ | ||
usingDirective = CheckFeatureAvailability(usingDirective, MessageID.IDS_FeatureUsingStatic); | ||
} | ||
|
||
if (globalToken != null) | ||
{ | ||
usingDirective = CheckFeatureAvailability(usingDirective, MessageID.IDS_FeatureUsingGlobal); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: why put the diagnostic on the whole directive? I expected we'd check the LangVer when we eat the token above (line 756) and put the diagnostic on globalToken
(it's a little more specific) #ByDesign
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: why put the diagnostic on the whole directive? I expected we'd check the LangVer when we eat the token above (line 756) and put the diagnostic on globalToken (it's a little more specific)
I am following the pattern already established for the static
keyword.
In reply to: 581664800 [](ancestors = 581664800)
var @using = this.ParseUsingDirective(); | ||
if (seen > NamespaceParts.Usings) | ||
{ | ||
@using = this.AddError(@using, ErrorCode.ERR_UsingAfterElements); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I recall correctly, adding an order error during parsing (as opposed to binding) has impact on incremental parsing that we generally want to avoid.
On the other hand, it looks like we already do it for top-level statements.
https://github.com/dotnet/roslyn/blob/master/docs/compilers/Design/Parser.md#do-not-use-ambient-context-to-direct-the-behavior-of-the-parser #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I recall correctly, adding an order error during parsing (as opposed to binding) has impact on incremental parsing that we generally want to avoid.
this is true. however, in this case, this is the right thing to do. We effectively have no place to put this using-directive as we're now past the location in the CompliationUnitSyntax where we could store them. So we instead have to break this down and attach to whatever real construct we find.
If we had made CompilationUnitSyntax just have a list of generic member nodes, we could have potentially kept the using directive here and error'ed later. However, that would have come with the negative of not having a nice strongly typed API for CompilationUnit that explicitly breaks out the different types of children. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I recall correctly, adding an order error during parsing (as opposed to binding) has impact on incremental parsing that we generally want to avoid.
This is a preexisting behavior of the parser. No change is introduced here. The code is simply extracted into a local function and reused.
In reply to: 581664827 [](ancestors = 581664827)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM Thanks (iteration 1)
@@ -6600,4 +6600,13 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ | |||
<data name="ERR_FunctionPointerTypesInAttributeNotSupported" xml:space="preserve"> | |||
<value>Using a function pointer type in a 'typeof' in an attribute is not supported.</value> | |||
</data> | |||
<data name="IDS_FeatureUsingGlobal" xml:space="preserve"> | |||
<value>global using directive</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this have a comment for localization team? #WontFix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this have a comment for localization team?
Historically we do not do this.
In reply to: 581753713 [](ancestors = 581753713)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AlekseyTs There are few resources that add similar comments for loc team:
<comment>UnmanagedCallersOnly is not localizable.</comment> |
This results in better translations. Was there a reason to not do this? (I see the resources I'm referring to are very very recent) #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was there a reason to not do this?
In my opinion there was no a good reason to add those comments.
In reply to: 582073782 [](ancestors = 582073782)
@dotnet/roslyn-compiler Please review, need a second sign-off. |
@@ -53,6 +57,14 @@ public bool HasAssemblyAttributes | |||
} | |||
} | |||
|
|||
public override bool HasGlobalUsings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does SingleNamespaceDeclarationEx
need to override this as well? I'm not sure what SingleNamespaceDeclarationEx
is used for, so just noting about it. #ByDesign
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does SingleNamespaceDeclarationEx need to override this as well? I'm not sure what SingleNamespaceDeclarationEx is used for, so just noting about it.
Namespace declarations are not allowed to have Global Using directives. For the purpose of error recovery all usings there will be treated as non-global, therefore, there are no Global Usings there.
In reply to: 582082881 [](ancestors = 582082881)
@@ -10106,7 +10107,7 @@ private static ExternAliasDirectiveSyntax GenerateExternAliasDirective() | |||
=> SyntaxFactory.ExternAliasDirective(SyntaxFactory.Token(SyntaxKind.ExternKeyword), SyntaxFactory.Token(SyntaxKind.AliasKeyword), SyntaxFactory.Identifier("Identifier"), SyntaxFactory.Token(SyntaxKind.SemicolonToken)); | |||
|
|||
private static UsingDirectiveSyntax GenerateUsingDirective() | |||
=> SyntaxFactory.UsingDirective(SyntaxFactory.Token(SyntaxKind.UsingKeyword), default(SyntaxToken), default(NameEqualsSyntax), GenerateIdentifierName(), SyntaxFactory.Token(SyntaxKind.SemicolonToken)); | |||
=> SyntaxFactory.UsingDirective(default(SyntaxToken), SyntaxFactory.Token(SyntaxKind.UsingKeyword), default(SyntaxToken), default(NameEqualsSyntax), GenerateIdentifierName(), SyntaxFactory.Token(SyntaxKind.SemicolonToken)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: the old overload is now not tested. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: the old overload is now not tested.
I find existing usage of that overload in the solution sufficient to provide coverage.
In reply to: 582088799 [](ancestors = 582088799)
Test plan: #51307