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

Add some EE and EnC tests for primary constructors #66677

Conversation

AlekseyTs
Copy link
Contributor

This change also flags as rude EnC edits that might result in changes around captured primary constructor parameters:

  • Adding a capture
  • Removing a capture
  • Changing type of a captured parameter
  • Etc.

The check is not meant to be able to accurately detect “safe” edits. The primary goal is to not let “unsafe” edits through.

This change also flags as rude EnC edits that might result in changes around captured primary constructor parameters:
- Adding a capture
- Removing a capture
- Changing type of a captured parameter
- Etc.

The check is not meant to be able to accurately detect “safe” edits. The primary goal is to not let “unsafe” edits through.
@AlekseyTs
Copy link
Contributor Author

@cston, @jjonescz, @dotnet/roslyn-compiler Please review.

@AlekseyTs
Copy link
Contributor Author

@cston, @dotnet/roslyn-compiler For the second review.

Copy link
Member

@tmat tmat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

{
var container = symbol.ContainingSymbol;

if (container is IMethodSymbol { IsImplicitlyDeclared: false, MethodKind: MethodKind.Constructor })
Copy link
Member

@cston cston Feb 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if

Is this treating any parameter of an explicit constructor as a rude edit when containing type has a primary constructor? Is that expected for a parameter of a constructor other than the primary constructor?

If this is a temporary restriction, consider adding a PROTOTYPE comment. #Resolved

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any edit to a class with primary ctor is a rude edit for now.

Copy link
Contributor Author

@AlekseyTs AlekseyTs Feb 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this treating any parameter of an explicit constructor as a rude edit when containing type has a primary constructor?

No. Only for a primary constructor.

Is that expected for a parameter of a constructor other than the primary constructor?

It is not and those are ignored. But as the PR comment says, there is no goal to enable any EnC scenarios in a class/struct with a primary constructor. The goal is to error on the safe side and disable EnC in them. So, if the change were to treat as rude any edit for parameter of a constructor other than the primary constructor, that would be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a temporary restriction, consider adding a PROTOTYPE comment.

The existence of this whole method is temporary. And I have PROTOTYPE comments where it is used. I do not expect it to survive once real EnC support is implemented.

{
var container = symbol.ContainingSymbol;

if (container is { Kind: SymbolKind.NamedType, IsImplicitlyDeclared: false })
Copy link
Member

@cston cston Feb 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if

Is this treating edits to members as rude edit when the containing type has a primary constructor?

If this is a temporary restriction, consider adding a PROTOTYPE comment. #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this treating edits to members as rude edit when the containing type has a primary constructor?

Yes.

If this is a temporary restriction, consider adding a PROTOTYPE comment.

The comments are added at the call sites. The whole method is temporary.

Diagnostic(RudeEditKind.Update, "long a", FeaturesResources.parameter));
}

#endregion
Copy link
Member

@cston cston Feb 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#endregion

Consider testing edits of explicit constructors other than the primary constructor, and edits of other members such as instance and static methods and fields. #Resolved

Copy link
Contributor Author

@AlekseyTs AlekseyTs Feb 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider testing edits of explicit constructors other than the primary constructor, and edits of other members such as instance and static methods and fields.

Testing of field initializers is not particularly interesting at the moment because they do not change capturing of primary constructor parameters. Also, at the moment, I do not care if their edits are flagged as rude edits or not. The goal is to error on the safe side.

Same goes for static methods.

Explicit constructors other than the primary constructors cannot refer to primary constructor parameters. So, same as for fields, I do not care what happens for them at the moment.

Addition/removal/edit of instance methods is covered. For example, PrimaryConstructors_01, PrimaryConstructors_02, PrimaryConstructors_03.

@AlekseyTs AlekseyTs merged commit 5af6535 into dotnet:features/PrimaryConstructors Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants