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

Use 'Throw' expression causes erroneous code #19507

Closed
znakeeye opened this issue May 15, 2017 · 2 comments
Closed

Use 'Throw' expression causes erroneous code #19507

znakeeye opened this issue May 15, 2017 · 2 comments
Labels
Area-IDE Bug Resolution-Duplicate The described behavior is tracked in another issue

Comments

@znakeeye
Copy link

znakeeye commented May 15, 2017

Version Used: 15.2 (26430.4)

Steps to Reproduce:

public Foo(T bar)
{
	if (bar == null)  // Use 'Throw' expression here...
	{
		throw new ArgumentNullException(nameof(bar));
	}
}

Error CS0019 Operator '??' cannot be applied to operands of type 'T' and '<throw expression>'

However, if I add a constraint on T in my class it works:

public sealed class Foo<TClass> where TClass : class
{}

Expected Behavior:
The "Use Throw expression" command should not be available or it should complain about the type. Maybe suggest adding the "where"-constraint above?

Actual Behavior:
Compilation error CS0019.

@sharwell sharwell added Area-IDE Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it labels May 15, 2017
@sharwell
Copy link
Member

It appears our analyzer is ignoring the rule described in #17754.

@Pilchie
Copy link
Member

Pilchie commented May 15, 2017

Already fixed for 15.3 as part of #18178.

@Pilchie Pilchie closed this as completed May 15, 2017
@Pilchie Pilchie added the Resolution-Duplicate The described behavior is tracked in another issue label May 15, 2017
@sharwell sharwell removed the help wanted The issue is "up for grabs" - add a comment if you are interested in working on it label May 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Bug Resolution-Duplicate The described behavior is tracked in another issue
Projects
None yet
Development

No branches or pull requests

3 participants