-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Invert the binding order of InitializerExpressions and CreationExpressions #30805
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34493,6 +34493,53 @@ public class C | |
"); | ||
Assert.Null(model.GetOperation(node3).Parent); | ||
} | ||
|
||
[Fact] | ||
public void OutVarInConstructorUsedInObjectInitializer() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have a similar test for collection initializers? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added OutVarInConstructorUsedInCollectionInitializer |
||
{ | ||
var source = | ||
@" | ||
public class C | ||
{ | ||
public int Number { get; set; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: space before brace There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
|
||
public C(out int n) | ||
{ | ||
n = 1; | ||
} | ||
|
||
public static void Main() | ||
{ | ||
C c = new C(out var i) { Number = i }; | ||
System.Console.WriteLine(c.Number); | ||
} | ||
} | ||
"; | ||
CompileAndVerify(source, expectedOutput: @"1"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: you could just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, this was just copy/paste from the other tests. Cleaned up. |
||
|
||
[Fact] | ||
public void OutVarInConstructorUsedInCollectionInitializer() | ||
{ | ||
var source = | ||
@" | ||
public class C : System.Collections.Generic.List<int> | ||
{ | ||
public C(out int n) | ||
{ | ||
n = 1; | ||
} | ||
|
||
public static void Main() | ||
{ | ||
C c = new C(out var i) { i, i, i }; | ||
System.Console.WriteLine(c[0]); | ||
} | ||
} | ||
"; | ||
CompileAndVerify(source, expectedOutput: @"1"); | ||
} | ||
|
||
} | ||
|
||
internal static class OutVarTestsExtensions | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case
node.Initializer is null
thediagnostics
parameter won't be used. Should we assert that it's empty in that case?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know that it will definitely be empty... It gets passed in from much higher up the stack. All we know is that we wouldn't add anything to it, but the code is simple enough that it seems trivially obvious we haven't changed it in the non-initializer case?