-
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
[Proposal]: breaking point for C# Primary Constructor #67796
Comments
There are 3 issues here:
Repro: var s = new S(1, 2);
var p = new P(1, 2);
Console.WriteLine();
record struct S(int A, int B);
struct P(int A, int B) { } Run and keep pressing 1234Compiler issue - missing sequence points (initializer of P is skipped): 56
Repro: place cursor on
The sequence points of
Sequence points of
I think we could add hidden sequence point to |
I wouldn't say that. It looks to me that the issue is not specific to a particular flavor of a primary constructor, record or not. If a primary constructor doesn't have any user code, no sequence points generated for its body. For example, debugger doesn't stop for this record.
Bottom line, this doesn't look like a new issue to me. |
Ok, it may work accidentally for some records and not for others, so might not be new. That doesn't mean it shouldn't be fixed (possibly by removing the existing sequence points generated for records, if we don't want to step into the ctor). |
No argument here. |
@tmat indeed I didn't notice one can step into record primary constructor parameter declaration. Issue 1) No breaking point can be set with F9 in this context: Issue 2) I cannot step-into with F11 in this context: Issue 3) No breaking point can be set with F9 in this context: |
In my case, the object instantiation would be from the DI container, so it is necessary to place a breakpoint at the type definition level to inspect it during the debugging process. Otherwise, I need to traverse through a hierarchy of instances to start from the invocation point (Application -> View -> ViewModel). This is just for the sample created. A real-world example would be much more complex. As we assess this feature to be useful esp for Services where the constructor parameter just gets assigned to the read-only field for its lifetime. And most of the time, the parameter would be used in another command, which is independent of instantiation, unlike the property where the value would be set instantly. So need an option that addresses this issue before this feature hits GA. |
Breakpoints in primary constructors are implemented in VS 17.8 Preview 1: #68765 |
Glad that it's getting addressed. Clarify whether v17.8 is planned to release before/alongside .NET 8 GA. |
I was investigating C# 12
![C# 12 class and struct Primary Constructor and breakpoint](https://user-images.githubusercontent.com/511445/231777497-08b92683-39f9-4c0a-b92d-d3671e735991.png)
class
andstruct
primary constructors and figured out that no breakpoint can be set, unless a parameter is used within a property initialization. It can certainly be useful to break upon a primary constructor, the same way it is useful to be able to break upon a propertyget;
orset;
:The text was updated successfully, but these errors were encountered: