Skip to content

Work Around for multiple inheritance #14892

Description

@Xpyder

Summary of the new feature/enhancement

Currently powershell is unable to implement Composition Over Inheritance because of a lack of support for custom "interfaces"

There is a way to get it to work, but it only works when running the code by hand, not in automated scripts

Proposed technical implementation details (optional)

The issue with the workaround boils down to a problem in the parser error: InterfaceNameExpected
It fails to recognize that using Add-Type will add types, instead it incorrectly assumes the given type will not be available

I think we should either allow a keyword to override this error, or educate the parser on the usage of Add-Type

Examples

I have included 3 examples:
A single file script that fails when run as a whole, but works if you manually run it line by line
A split that works, but is forced to have an incorrect dependency tree
A split that fails, because it's using a correct dependency tree

Note: The splits use dot sourcing, you'll need to adjust the paths to the appropriate folders on your computer
Fail - Single File.zip
Success - Bad Dependancy layout.zip
Fail - Good Dependency Layout.zip

Related issues

PowerShell/PowerShell-RFC#152
#2223

Activity

  1. added
    Issue-Enhancementthe issue is more of a feature request than a bug
    Needs-TriageThe issue is new and needs to be triaged by a work group.
    on Feb 23, 2021
  2. Xpyder commented on Feb 23, 2021

    @Xpyder
    Author

    I've included a readme.txt with each set giving a summary of what it's showing and why it's meaningful

  3. Xpyder commented on Feb 23, 2021

    @Xpyder
    Author

    A possible work around for this might be to have the parser pause while the dot sources are run

    so for example:

    • Main.ps1 parsing starts
    • Main.ps1 parsing pauses while dot sources are run
      • Tests.ps1 parsing starts
      • Tests.ps1 parsing pauses while dot sources are run
        • Classes.ps1 parsing starts
        • Classes.ps1 parsing pauses while dot sources are run
          • Interfaces.ps1 parsing starts
          • Add-Type is run
          • Interfaces.ps1 finishes
        • Classes.ps1 parsing continues
        • Parser correctly recognizes CustomInterface exists
  4. daxian-dbw commented on May 6, 2021

    @daxian-dbw
    Member

    Language working group:
    This issue is a duplicate of #2223. Allowing to define interface in powershell directly is the right way to go.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugWG-Languageparser, language semantics

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions