Skip to content
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

Regression: SyntaxFactory.UsingDirective overload always throws #68761

Closed
GrahamTheCoder opened this issue Jun 24, 2023 · 1 comment · Fixed by #68762
Closed

Regression: SyntaxFactory.UsingDirective overload always throws #68761

GrahamTheCoder opened this issue Jun 24, 2023 · 1 comment · Fixed by #68762
Assignees
Labels
Area-Compilers Bug Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Milestone

Comments

@GrahamTheCoder
Copy link
Contributor

GrahamTheCoder commented Jun 24, 2023

Version Used:
Version 17.7.0 Preview 2.0

Steps to Reproduce:

  1. Call Microsoft.CodeAnalysis.CSharp.SyntaxFactory.UsingDirective(SyntaxToken staticKeyword, NameEqualsSyntax alias, NameSyntax name) with any valid parameters
  2. throws ArgumentException("usingKeyword")

Expected Behavior:
As previously: Construct and pass a valid Token(usingKeyword)

Actual Behavior:
Constructs and passes a default(SyntaxToken) which causes the called code to always throw

Other details

The bug is here:

=> UsingDirective(globalKeyword: default, usingKeyword: default, staticKeyword, unsafeKeyword: default, alias, namespaceOrType: name, semicolonToken: default);

It passes through default, to an overload that in the generated syntax factory that throws unless the syntax kind of that parameter is SyntaxKind.UsingKeyword

The code was added in: c8d3925#diff-95477edd7a2f9bf55ac156fbeb22d71f973b06dc20a7034b373e8c2e8341d6f0

Bug originally reported here: icsharpcode/CodeConverter#1019
Unit test would probably go in Microsoft.CodeAnalysis.CSharp.UnitTests.SyntaxFactoryTests and look something like:

        [Fact]
        public void UsingDirective()
        {
            var someValidName = SyntaxFactory.ParseName("System.String");
            var usingDirective = SyntaxFactory.UsingDirective(SyntaxFactory.Token(SyntaxKind.StaticKeyword), default(NameEqualsSyntax), someValidName);
            Assert.Equal("using static System.String;", usingDirective.ToString());
        }

[jcouv update:] Relates to test plan #56323

@CyrusNajmabadi
Copy link
Member

@GrahamTheCoder def feel free to submit a fix too. It will help expedite things!

@jcouv jcouv added Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it labels Jun 26, 2023
@jcouv jcouv added this to the 17.7 milestone Jun 26, 2023
@jcouv jcouv removed the untriaged Issues and PRs which have not yet been triaged by a lead label Jun 26, 2023
@sharwell sharwell modified the milestones: 17.7, Next Jun 27, 2023
@sharwell sharwell added Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented and removed help wanted The issue is "up for grabs" - add a comment if you are interested in working on it labels Jun 27, 2023
@RikkiGibson RikkiGibson modified the milestones: Next, 17.7 P3 Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Bug Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants