KEMBAR78
Make inherited protected internal instance members accessible in class scope. by mawosoft · Pull Request #25245 · PowerShell/PowerShell · GitHub
Skip to content

Conversation

@mawosoft
Copy link
Contributor

@mawosoft mawosoft commented Mar 27, 2025

PR Summary

This PR enables PowerShell classes to access inherited protected internal instance members in addition to protected ones. It expands the existing scope checks for IsFamily to check for both IsFamily and IsFamilyOrAssembly.

Fixes #24898.

PR Context

After switching to .NET 9 in Powershell 7.5, PowerShell classes can no longer call $this.MemberwiseClone() because the API signature of the method in the .NET SDK was changed from protected to protected internal. Other APIs may be affected as well, but this is the most notable problem, causing a breaking change when existing scripts switch from PowerShell 7.4 to 7.5 or newer.

To speed up the review process, this PR makes only minimal changes adressing access to inherited instance members. These changes should be backported to 7.5 immediately (bugfix). A backport to 7.4 should also be considered (enhancement).

Future considerations for inherited static members

At the moment, PowerShell classes can only access public inherited static members. If it is desirable to allow access to protected and protected internal static members as well, I already have a separate PR ready to submit, after this one has been merged.

PR Checklist

@mawosoft

This comment was marked as outdated.

@iSazonov iSazonov added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Mar 27, 2025
@iSazonov
Copy link
Collaborator

@mawosoft Please look CI failures. I see only 8 failed tests.

@mawosoft

This comment was marked as outdated.

@iSazonov iSazonov requested a review from daxian-dbw March 27, 2025 16:44
@iSazonov
Copy link
Collaborator

@mawosoft Let's wait MSFT team member's review. It can take a long time.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Review - Needed The PR is being reviewed label Apr 4, 2025
mawosoft added 4 commits April 7, 2025 19:08
- Remove tests for static members because this PR is limited to instance members.
- Add tests for accessing instance members dynamically.
- Clean up code and clarify test descriptions.
@mawosoft mawosoft changed the title WIP: Make protected internal base class members accessible in class scope. Make inherited protected internal instance members accessible in class scope. Apr 7, 2025
@mawosoft
Copy link
Contributor Author

mawosoft commented Apr 7, 2025

@iSazonov, @SeeminglyScience, @daxian-dbw

To speed up the review process, this PR makes only minimal changes adressing access to inherited instance members. These changes should be backported to 7.5 immediately (bugfix). A backport to 7.4 should also be considered (enhancement).

Future considerations for inherited static members

At the moment, PowerShell classes can only access public inherited static members. If it is desirable to allow access to protected and protected internal static members as well, I already have a separate PR ready to submit, after this one has been merged.

See PR description.

@iSazonov
Copy link
Collaborator

iSazonov commented Apr 8, 2025

After switching to .NET 9 in Powershell 7.5, PowerShell classes can no longer call $this.MemberwiseClone()

Can we have a test to ensure this now works?

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Review - Needed The PR is being reviewed label Apr 8, 2025
@mawosoft
Copy link
Contributor Author

mawosoft commented Apr 8, 2025

Can we have a test to ensure this now works?

@iSazonov Done.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Review - Needed The PR is being reviewed label Apr 15, 2025
@FabienTschanz
Copy link

Any chance we can get this PR reviewed? Thank you!

@daxian-dbw
Copy link
Member

Sorry for the long delay! I will make sure review this PR next Monday.

Copy link
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

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

@mawosoft Again, sorry for the long delay! The product changes look good to me, but I left 2 comments in the test changes. Please take a look, thanks!

@microsoft-github-policy-service microsoft-github-policy-service bot added Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept and removed Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept labels May 12, 2025
@daxian-dbw
Copy link
Member

/azp run PowerShell-CI-linux-packaging PowerShell-Windows-Packaging-CI

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@daxian-dbw daxian-dbw merged commit eb1cc6d into PowerShell:master May 12, 2025
38 checks passed
@github-project-automation github-project-automation bot moved this from PR In Progress to Done in PowerShell Team Reviews/Investigations May 12, 2025
@microsoft-github-policy-service
Copy link
Contributor

microsoft-github-policy-service bot commented May 12, 2025

📣 Hey @@mawosoft, how did we do? We would love to hear your feedback with the link below! 🗣️

🔗 https://aka.ms/PSRepoFeedback

@mawosoft
Copy link
Contributor Author

@daxian-dbw What are your thoughts on doing this for static members as well? See "future considerations" in the PR Context at the top.

Also, don't forget to backport to 7.5 :) Not sure how that selection process works here.

@daxian-dbw
Copy link
Member

I agree to support the same for static members for the sake of consistency. Please submit a new PR for that. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backport-7.4.x-Migrated CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

Development

Successfully merging this pull request may close these issues.

MemberwiseClone is missing after upgrade to powershell 7.5.0

5 participants