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

IDE0270 triggers over a #if #70514

Closed
vsfeedback opened this issue Oct 23, 2023 · 0 comments · Fixed by #76173
Closed

IDE0270 triggers over a #if #70514

vsfeedback opened this issue Oct 23, 2023 · 0 comments · Fixed by #76173
Labels
Milestone

Comments

@vsfeedback
Copy link

This issue has been moved from a ticket on Developer Community.


[severity:It bothers me. A fix would be nice]
My code:

var local = VirtualProperty;

#if DEBUG
if (local == null)// IDE0270.
    throw new Exception();
#endif

The suggested fix gives this:

var local = VirtualProperty ?? throw new Exception();

#if DEBUG
#endif

That's obviously a change in behaviour for moving the exception out of the #if, but it shouldn't be trying to use a coalesce expression at all because it would require the ; to be after the #endif which is super ugly:

var local = VirtualProperty
#if DEBUG
    ?? throw new Exception()
#endif
    ;

Leaving my original code without any suggestion would be ideal.


Original Comments

Feedback Bot on 10/23/2023, 00:11 AM:

(private comment, text removed)


Original Solutions

(no solutions)

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Oct 23, 2023
@CyrusNajmabadi CyrusNajmabadi added the Feature - IDE0270 Use coalesce expression label Oct 23, 2023
@arunchndr arunchndr added Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 6, 2024
@arunchndr arunchndr added this to the Backlog milestone Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants