Skip to content

Update ShouldImplementProperty() to flatten interface hierarchy - #8382

Merged
Dongbo Wang (daxian-dbw) merged 7 commits into
PowerShell:masterfrom
IISResetMe:patch/virtual-interface-properties-2
Feb 19, 2019
Merged

Dongbo Wang (daxian-dbw) merged 7 commits into
PowerShell:masterfrom
IISResetMe:patch/virtual-interface-properties-2

Conversation

@IISResetMe

@IISResetMe Mathias R. Jessen (IISResetMe) commented Dec 2, 2018 •

Copy link
Copy Markdown
Collaborator

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

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.
@iSazonov

Copy link
Copy Markdown
Collaborator

Mathias R. Jessen (@IISResetMe) Please add a commit with [Feature] in title to run feature tests.

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

Copy link
Copy Markdown
Collaborator Author

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

@vexx32

Copy link
Copy Markdown
Collaborator

Mathias R. Jessen (@IISResetMe) push an empty commit that contains the tag [Feature] in the commit message itself, yep! 😄

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

stale Bot commented Jan 6, 2019

Copy link
Copy Markdown

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 Stale label Jan 6, 2019
@iSazonov

Copy link
Copy Markdown
Collaborator

Mathias R. Jessen (@IISResetMe) Dongbo Wang (@daxian-dbw) Could you please continue?

@stale stale Bot removed the Stale label Jan 6, 2019
@IISResetMe

Copy link
Copy Markdown
Collaborator Author

Ilya (@iSazonov) I believe I've addressed all of Dongbo Wang (@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

Ilya (iSazonov) commented Jan 13, 2019 •

Copy link
Copy Markdown
Collaborator

Mathias R. Jessen (@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.

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

@IISResetMe

Copy link
Copy Markdown
Collaborator Author

[...] 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

stale Bot commented Feb 12, 2019

Copy link
Copy Markdown

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 Stale label Feb 12, 2019
@IISResetMe

Copy link
Copy Markdown
Collaborator Author

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

@stale stale Bot removed the Stale label Feb 15, 2019

@daxian-dbw Dongbo Wang (daxian-dbw) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

@daxian-dbw

Copy link
Copy Markdown
Member

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

@daxian-dbw
Dongbo Wang (daxian-dbw) merged commit 0a57021 into PowerShell:master Feb 19, 2019
@iSazonov Ilya (iSazonov) added the CL-Engine Indicates that a PR should be marked as an engine change in the Change Log label Feb 20, 2019
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
… 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

Labels

CL-Engine Indicates that a PR should be marked as an engine change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants