★ wanayoo — archive 1999 https://github.com/PowerShell/PowerShell/pull/8382Nouvelle recherche | Portail wanayoo
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

Update ShouldImplementProperty() to flatten interface hierarchy #8382

Merged

Conversation

Projects
None yet
5 participants
@IISResetMe
Copy link
Contributor

commented Dec 2, 2018

PR Summary

TypeBuilder.GetInterfaces(), as introduced in #8303 returns only the interfaces that was explicitly passed to its constructor, so the current implementation doesn't work for inherited interfaces:

  Add-Type 'public interface ITestBase { string Base {get;} }
            public interface ITest : ITestBase { string Test {get;} }'
  class MyClass : ITest
  {
    [string]$Test
    [string]$Base
  }

In this example, ShouldImplementProperty() won't resolve ITestBase.Base and type definition fails because get_Base() isn't virtual.
During compilation the interface hierarchy is flattened, so we only need to resolve one level of ancestral interfaces.

PR Checklist

IISResetMe added some commits Dec 2, 2018

Update ShouldImplementProperty() to flatten interface hierarchy
TypeBuilder.GetInterfaces() returns only the interfaces that was explicitly passed to its constructor, so the current implementation doesn't work for inherited interfaces:

  Add-Type 'public interface ITestBase { string Base {get;} }
            public interface ITest : ITestBase { string Test {get;} }'
  class : ITest
  {
    [string]$Test
    [string]$Base
  }

In this example, ShouldImplementProperty() won't resolve ITestBase.Base and type definition fails.
During compilation the interface hierarchy is flattened, so we only need to resolve one level of ancestral interfaces.

@IISResetMe IISResetMe requested review from BrucePay and daxian-dbw as code owners Dec 2, 2018

@iSazonov iSazonov requested a review from lzybkr Dec 3, 2018

@iSazonov

This comment has been minimized.

Copy link
Collaborator

commented Dec 3, 2018

@IISResetMe Please add a commit with [Feature] in title to run feature tests.

@IISResetMe IISResetMe changed the title Update ShouldImplementProperty() to flatten interface hierarchy [Feature] Update ShouldImplementProperty() to flatten interface hierarchy Dec 3, 2018

@IISResetMe

This comment has been minimized.

Copy link
Contributor Author

commented Dec 3, 2018

@iSazonov I think we'll need to push an empty commit (or close-reopen pr) to trigger the tests again

@vexx32

This comment has been minimized.

Copy link
Contributor

commented Dec 3, 2018

@IISResetMe push an empty commit that contains the tag [Feature] in the commit message itself, yep! 😄

IISResetMe added some commits Dec 5, 2018

Separate interface resolution from property enumeration in ShouldImpl…
…ementProperty

+ use Tuple.Create() instead of explicit constructor

@adityapatwardhan adityapatwardhan changed the title [Feature] Update ShouldImplementProperty() to flatten interface hierarchy Update ShouldImplementProperty() to flatten interface hierarchy Dec 6, 2018

IISResetMe added some commits Dec 6, 2018

@stale

This comment has been minimized.

Copy link

commented Jan 6, 2019

This PR has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed if no further activity occurs within 10 days.
Thank you for your contributions.
Community members are welcome to grab these works.

@stale stale bot added the Review - Abandoned label Jan 6, 2019

@iSazonov

This comment has been minimized.

Copy link
Collaborator

commented Jan 6, 2019

@IISResetMe @daxian-dbw Could you please continue?

@stale stale bot removed the Review - Abandoned label Jan 6, 2019

@IISResetMe

This comment has been minimized.

Copy link
Contributor Author

commented Jan 12, 2019

@iSazonov I believe I've addressed all of @daxian-dbw's remarks, the only thing left was to run the feature tests.

Am I expected to remove the Invoke-Expression statement from the test? 😕

@iSazonov

This comment has been minimized.

Copy link
Collaborator

commented Jan 13, 2019

@IISResetMe I think using Invoke-Expression haven't a security risk. The Codacy report is for custom scripts not tests. We have to align the settings.

@daxian-dbw Seems the PR is ready to merge. Please update your code review.

@IISResetMe

This comment has been minimized.

Copy link
Contributor Author

commented Jan 13, 2019

[...] The Codacy report is for custom scripts not tests. We have to align the settings.

Yeah, looks like we might want to include it only if .ps1 files that don't match *.tests?.ps1$ are changed

@stale

This comment has been minimized.

Copy link

commented Feb 12, 2019

This PR has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed if no further activity occurs within 10 days.
Thank you for your contributions.
Community members are welcome to grab these works.

@stale stale bot added the Review - Abandoned label Feb 12, 2019

@IISResetMe

This comment has been minimized.

Copy link
Contributor Author

commented Feb 15, 2019

@daxian-dbw had a chance to update this? :)

@stale stale bot removed the Review - Abandoned label Feb 15, 2019

@daxian-dbw
Copy link
Member

left a comment

Looks great. Sorry for being tardy in responding (was on a trip for the past 3 weeks).

@daxian-dbw

This comment has been minimized.

Copy link
Member

commented Feb 19, 2019

As for the Codacy report about Invoke-Expression, the Invoke-Expression command is needed as the interfaces are defined at runtime.

@daxian-dbw daxian-dbw merged commit 0a57021 into PowerShell:master Feb 19, 2019

6 of 7 checks passed

Codacy/PR Quality Review Not up to standards. This pull request quality could be better.
Details
CodeFactor No issues found.
Details
PowerShell-CI-linux #PR-8382-20181206.02 succeeded
Details
PowerShell-CI-macos #PR-8382-20181206.02 succeeded
Details
PowerShell-CI-spelling #PR-8382-20181206.02 succeeded
Details
PowerShell-CI-windows #PR-8382-20181206.02 succeeded
Details
license/cla All CLA requirements met.
Details

@iSazonov iSazonov added the CL-Engine label Feb 20, 2019

RDIL pushed a commit to RDIL/PowerShell that referenced this pull request Mar 13, 2019

Flatten interface hierarchy when generating properties that implement…
… interface properties (PowerShell#8382)

`TypeBuilder.GetInterfaces()` returns only the interfaces that was explicitly passed to its constructor, so we need to flatten the interface hierarchy in order to properly support inherited interfaces.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.