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

Correct the evaluation order of conversions in deconstructions #12400

Closed
jcouv opened this issue Jul 8, 2016 · 1 comment · Fixed by #62907
Closed

Correct the evaluation order of conversions in deconstructions #12400

jcouv opened this issue Jul 8, 2016 · 1 comment · Fixed by #62907
Assignees
Labels
4 - In Review A fix for the issue is submitted for review. Area-Compilers New Language Feature - Tuples Tuples

Comments

@jcouv
Copy link
Member

jcouv commented Jul 8, 2016

When deconstructing an object that has a Deconstruct method, the order of evaluation should be:

  1. evaluate the left-hand side for side-effects
  2. evaluate the right-hand side and evaluate the Deconstruct method (or methods in the case of nested deconstruction)
  3. convert all the results
  4. assign the results
  5. construct a tuple representing the result of the assignment
@Youssef1313
Copy link
Member

@jcouv This issue is still referenced in source.

[Fact(Skip = "https://github.com/dotnet/roslyn/issues/12400")]
[WorkItem(12400, "https://github.com/dotnet/roslyn/issues/12400")]
public void AssignWithPostfixOperator()
{
string source = @"
class C
{
int state = 1;
static void Main()
{
long x;
string y;
C c = new C();
(x, y) = c++;
System.Console.WriteLine(x + "" "" + y);
}
public void Deconstruct(out int a, out string b)
{
a = state;
b = ""hello"";
}
public static C operator ++(C c1)
{
return new C() { state = 2 };
}
}
";
// https://github.com/dotnet/roslyn/issues/12400
// we expect "2 hello" instead, which means the evaluation order is wrong
var comp = CompileAndVerify(source, expectedOutput: "1 hello");
comp.VerifyDiagnostics();
}

The test passes when unskipped, but there is a comment that says:

         // we expect "2 hello" instead, which means the evaluation order is wrong 

I don't quite get why "2 hello" is expected if we're using postfix operator?

@jcouv jcouv modified the milestones: 2.0 (Preview 5), 17.4 Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4 - In Review A fix for the issue is submitted for review. Area-Compilers New Language Feature - Tuples Tuples
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants