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

[C# language specification 7th edition] Incorrect rule for definite-assignment state for || expressions #1070

Open
fmdkara opened this issue Mar 31, 2024 · 1 comment
Assignees

Comments

@fmdkara
Copy link

fmdkara commented Mar 31, 2024

I downloaded the C# language specification 7th edition via https://ecma-international.org/publications-and-standards/standards/ecma-334/. In chapter 9.4.4.27 about definite-assignment state of || expressions, it was written

The definite-assignment state of v before expr_second is definitely assigned if and only if the state of
v after expr_first is either definitely assigned or “definitely assigned after true expression”.
Otherwise, it is not definitely assigned.

However, i believe that is incorrect, the correct one should be

The definite-assignment state of v before expr_second is definitely assigned if and only if the state of
v after expr_first is either definitely assigned or “definitely assigned after false expression”.
Otherwise, it is not definitely assigned.

Because if the former is correct, then v can be definitely-assigned when it shouldn't be, consider the following situation:

  1. The definite-assignment state of v after expr_first is definitely assigned after true expression
  2. expr_first is false
  3. expr_second is evaluated and the definite-assignment state of v before expr_second is definitely-assigned, however because number 1 and 2, then v is not actually assigned.

From the reason above, i believe that the former is incorrect and the latter is the correct one

@jskeet
Copy link
Contributor

jskeet commented Apr 2, 2024

Assigned to @gafter to confirm. The fact that it's currently the same for || as for && (both use "definitely assigned after true expression") rings alarm bells with me though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants