未验证 提交 0d0406b2 编写于 作者: N Neal Gafter 提交者: GitHub

Switch on enum type nested in generic type produces LangVersion error (#34911)

Fixes #34905
上级 aacb7137
......@@ -210,8 +210,7 @@ private BoundPattern BindDiscardPattern(DiscardPatternSyntax node, TypeSymbol in
{
var requiredVersion = MessageID.IDS_FeatureRecursivePatterns.RequiredVersion();
if (Compilation.LanguageVersion < requiredVersion &&
// A null pattern can be tested against a type that can be assigned null, even in C# 7.3
!(expression.ConstantValue == ConstantValue.Null && inputType.CanBeAssignedNull()))
!this.Conversions.ClassifyConversionFromExpression(expression, inputType, ref useSiteDiagnostics).IsImplicit)
{
diagnostics.Add(ErrorCode.ERR_ConstantPatternVsOpenType,
expression.Syntax.Location, inputType, expression.Display, new CSharpRequiredLanguageVersion(requiredVersion));
......
......@@ -2317,5 +2317,31 @@ static bool Test4(T t)
// return t is "frog"; // 3
Diagnostic(ErrorCode.ERR_ConstantPatternVsOpenType, @"""frog""").WithArguments("T", "string", "preview").WithLocation(17, 21));
}
[Fact]
[WorkItem(34905, "https://github.com/dotnet/roslyn/issues/34905")]
public void ConstantPatternVsUnconstrainedTypeParameter06()
{
var source =
@"public class C<T>
{
public enum E
{
V1, V2
}
public void M()
{
switch (default(E))
{
case E.V1:
break;
}
}
}
";
CreateCompilation(source, options: TestOptions.ReleaseDll).VerifyDiagnostics();
CreateCompilation(source, options: TestOptions.ReleaseDll, parseOptions: TestOptions.Regular7_3).VerifyDiagnostics();
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册