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

RCS1220 produces broken suggestion when pattern matching on System.Enum #942

Closed
NoahStolk opened this issue Aug 15, 2022 · 0 comments · Fixed by #943
Closed

RCS1220 produces broken suggestion when pattern matching on System.Enum #942

NoahStolk opened this issue Aug 15, 2022 · 0 comments · Fixed by #943

Comments

@NoahStolk
Copy link

NoahStolk commented Aug 15, 2022

Product and Version Used:

Roslynator.Analyzers 4.1.1

Steps to Reproduce:

Consider this method:

Enum? Example(object? value)
{
	if (value is Enum)
		return (Enum)value;

	return null;
}

RCS1220 "Use pattern matching instead of combination of 'is' operator and cast operator." is triggered, which is correct. However, it produces a broken suggestion:

if (value is Enum enum) // Does not compile
	return enum;

enum is a keyword, so this code does not compile. The same happens with other keywords, for example if you were to create a class named Static, it produces this code:

if (value is Static static) // Does not compile
	return static;

string (or String) seems to work correctly:

if (value is string x) // OK
	return x;

Actual Behavior:

if (value is Enum enum)
	return enum;

Expected Behavior:

if (value is Enum @enum)
	return @enum;

or

if (value is Enum x)
	return x;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants