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

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

Merged
merged 1 commit into from
Apr 10, 2019
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
3 changes: 1 addition & 2 deletions src/Compilers/CSharp/Portable/Binder/Binder_Patterns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,7 @@ internal BoundExpression ConvertPatternExpression(
{
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}