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

Merge release/dev16.7-preview1 to master #44001

Merged
2 commits merged into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.

using System.Diagnostics;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax
{
Expand Down Expand Up @@ -451,8 +450,9 @@ private bool ConvertTypeToExpression(TypeSyntax type, out ExpressionSyntax expr,
expr = s;
return true;
case QualifiedNameSyntax { Left: var left, dotToken: var dotToken, Right: var right }
when (permitTypeArguments || !(right is GenericNameSyntax)) && ConvertTypeToExpression(left, out var leftExpr, permitTypeArguments: true):
expr = _syntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, leftExpr, dotToken, right);
when (permitTypeArguments || !(right is GenericNameSyntax)):
var newLeft = ConvertTypeToExpression(left, out var leftExpr, permitTypeArguments: true) ? leftExpr : left;
expr = _syntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, newLeft, dotToken, right);
return true;
default:
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3340,5 +3340,32 @@ static void M(object o, bool c)
Diagnostic(ErrorCode.ERR_AsNullableType, "A[][]?").WithArguments("A[][]").WithLocation(16, 18)
);
}

[Fact, WorkItem(43960, "https://github.com/dotnet/roslyn/issues/43960")]
public void NamespaceQualifiedEnumConstantInSwitchCase()
{
var source =
@"enum E
{
A, B, C
}

class Class1
{
void M(E e)
{
switch (e)
{
case global::E.A: break;
case global::E.B: break;
case global::E.C: break;
}
}
}";
CreateCompilation(source, parseOptions: TestOptions.Regular7, options: TestOptions.ReleaseDll).VerifyDiagnostics(
);
CreatePatternCompilation(source, options: TestOptions.ReleaseDll).VerifyDiagnostics(
);
}
}
}
64 changes: 64 additions & 0 deletions src/Compilers/CSharp/Test/Syntax/Parsing/PatternParsingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10942,5 +10942,69 @@ public void OrPatternAssociativity_01()
}
EOF();
}

[Fact, WorkItem(43960, "https://github.com/dotnet/roslyn/issues/43960")]
public void NamespaceQualifiedEnumConstantInSwitchCase()
{
var source = @"switch (e) { case global::E.A: break; }";
UsingStatement(source,
TestOptions.RegularWithPatternCombinators
);
verifyTree();
UsingStatement(source,
TestOptions.RegularWithoutPatternCombinators
);
verifyTree();

void verifyTree()
{
N(SyntaxKind.SwitchStatement);
{
N(SyntaxKind.SwitchKeyword);
N(SyntaxKind.OpenParenToken);
N(SyntaxKind.IdentifierName);
{
N(SyntaxKind.IdentifierToken, "e");
}
N(SyntaxKind.CloseParenToken);
N(SyntaxKind.OpenBraceToken);
N(SyntaxKind.SwitchSection);
{
N(SyntaxKind.CaseSwitchLabel);
{
N(SyntaxKind.CaseKeyword);
N(SyntaxKind.SimpleMemberAccessExpression);
{
N(SyntaxKind.AliasQualifiedName);
{
N(SyntaxKind.IdentifierName);
{
N(SyntaxKind.GlobalKeyword);
}
N(SyntaxKind.ColonColonToken);
N(SyntaxKind.IdentifierName);
{
N(SyntaxKind.IdentifierToken, "E");
}
}
N(SyntaxKind.DotToken);
N(SyntaxKind.IdentifierName);
{
N(SyntaxKind.IdentifierToken, "A");
}
}
N(SyntaxKind.ColonToken);
}
N(SyntaxKind.BreakStatement);
{
N(SyntaxKind.BreakKeyword);
N(SyntaxKind.SemicolonToken);
}
}
N(SyntaxKind.CloseBraceToken);
}
EOF();
}
}
}
}