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

Improve condition logic with conditional access expression #54467

Closed
MatthieuMEZIL opened this issue Jun 29, 2021 · 2 comments
Closed

Improve condition logic with conditional access expression #54467

MatthieuMEZIL opened this issue Jun 29, 2021 · 2 comments
Labels
Area-Compilers Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@MatthieuMEZIL
Copy link

If the expression is myDictionnary.TryGetValue(key, out T value) == true ? value : value2, compilation succeeds.
However, if I use myDictionnary?.TryGetValue(key, out T value) == true ? value : value2, compilation fails with the following error:
CS0165 Use of unassigned local variable 'value'.
I believe the logic here could be improved, supporting conditional access expression, to avoid this error.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 29, 2021
@Youssef1313
Copy link
Member

I believe this is already implemented for C# 10. Proposal: dotnet/csharplang#4465

@RikkiGibson RikkiGibson added the Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented label Jun 29, 2021
@RikkiGibson
Copy link
Contributor

Thanks for filing the issue. This was fixed by #54004. Shipping in dev17 preview 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

3 participants