GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Update ShouldImplementProperty() to flatten interface hierarchy by IISResetMe · Pull Request #8382 · PowerShell/PowerShell

Conversation

@IISResetMe

@IISResetMe Mathias R. Jessen (IISResetMe) commented Dec 2, 2018 •
edited by iSazonov
Loading

Uh oh!

There was an error while loading. Please reload this page.

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

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Change is not breaking
  • Make sure all .h, .cpp, .cs, .ps1 and .psm1 files have the correct copyright header
  • This PR is ready to merge and is not Work in Progress.
    • If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready.
  • User-facing changes
    • Not Applicable
    • OR
    • User-facing Documentation needed
      • Issue filed - Issue link:
  • Testing - New and feature
    • Not Applicable or can only be tested interactively
    • OR
    • Make sure you've added a new test if existing tests do not effectively test the code changed
      • Add [feature] if the change is significant or affects feature tests

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

iSazonov reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Mathias R. Jessen (IISResetMe) added 2 commits December 2, 2018 19:16
@IISResetMe
Update ShouldImplementProperty() to flatten interface hierarchy
2bab38e
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
Add test for inherited interfaces
87191f2
@IISResetMe
Mathias R. Jessen (IISResetMe) requested review from Bruce Payette (BrucePay) and Dongbo Wang (daxian-dbw) as code owners December 2, 2018 23:17
@iSazonov
Ilya (iSazonov) requested a review from Jason Shirk (lzybkr) December 3, 2018 04:15
@iSazonov

Ilya (iSazonov) commented Dec 3, 2018

Copy link
Copy Markdown
Collaborator

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@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

Mathias R. Jessen (IISResetMe) commented Dec 3, 2018

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vexx32

Rain Sallow (/u/ta11ow) (vexx32) commented Dec 3, 2018

Copy link
Copy Markdown
Collaborator

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@IISResetMe
[Feature] triggering dem feature tests
720c9ec
iSazonov
Ilya (iSazonov) reviewed Dec 4, 2018
View reviewed changes
Comment thread src/System.Management.Automation/engine/parser/PSType.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

daxian-dbw
Dongbo Wang (daxian-dbw) reviewed Dec 5, 2018
View reviewed changes
Comment thread src/System.Management.Automation/engine/parser/PSType.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/System.Management.Automation/engine/parser/PSType.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/powershell/Language/Classes/scripting.Classes.inheritance.tests.ps1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Mathias R. Jessen (IISResetMe) and others added 2 commits December 5, 2018 12:44
@IISResetMe
Separate interface resolution from property enumeration in ShouldImpl…
283eb55
…ementProperty

+ use Tuple.Create() instead of explicit constructor
@IISResetMe
Remove redundant instantiation of test class
e003052
@adityapatwardhan Aditya Patwardhan (adityapatwardhan) changed the title [Feature] Update ShouldImplementProperty() to flatten interface hierarchy Update ShouldImplementProperty() to flatten interface hierarchy Dec 6, 2018
Mathias R. Jessen (IISResetMe) added 2 commits December 6, 2018 23:03
@IISResetMe
Merge branch 'patch/virtual-interface-properties-2' of https://github…
4a353ef
….com/IISResetMe/PowerShell into patch/virtual-interface-properties-2
@IISResetMe
Fix CodeFactor issue (SA1513)
130beca
@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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stale stale Bot added the Stale label Jan 6, 2019
@iSazonov

Ilya (iSazonov) commented Jan 6, 2019

Copy link
Copy Markdown
Collaborator

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Mathias R. Jessen (IISResetMe) commented Jan 12, 2019

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? 😕

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov Ilya (iSazonov) assigned Dongbo Wang (daxian-dbw) Jan 13, 2019
@iSazonov

Ilya (iSazonov) commented Jan 13, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@IISResetMe

Mathias R. Jessen (IISResetMe) commented Jan 13, 2019

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stale stale Bot added the Stale label Feb 12, 2019
@IISResetMe

Mathias R. Jessen (IISResetMe) commented Feb 15, 2019

Copy link
Copy Markdown
Collaborator Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stale stale Bot removed the Stale label Feb 15, 2019
daxian-dbw
Dongbo Wang (daxian-dbw) approved these changes Feb 19, 2019
View reviewed changes

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

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

IISResetMe reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@daxian-dbw

Dongbo Wang (daxian-dbw) commented Feb 19, 2019

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@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
@IISResetMe @daxian-dbw
Flatten interface hierarchy when generating properties that implement…
6fc5c04
… 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

Reviewers

@iSazonov Ilya (iSazonov) iSazonov left review comments
@daxian-dbw Dongbo Wang (daxian-dbw) daxian-dbw approved these changes
@BrucePay Bruce Payette (BrucePay) Awaiting requested review from BrucePay
@lzybkr Jason Shirk (lzybkr) Awaiting requested review from lzybkr

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@daxian-dbw Dongbo Wang (daxian-dbw)

Labels

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

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@IISResetMe @iSazonov @vexx32 @daxian-dbw @lzybkr
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.