WIP: Allow self-referential generic type parameters in interface list#12863
WIP: Allow self-referential generic type parameters in interface list#12863IISResetMe wants to merge 3 commits intoPowerShell:masterfrom
Conversation
There was a problem hiding this comment.
@IISResetMe, your last commit had 4 failures in PowerShell-CI-linux
Error occurred in test script '/home/vsts/work/1/s/test/powershell/Language/Classes/scripting.Classes.inheritance.tests.ps1'
Object reference not set to an instance of an object.
at <ScriptBlock>, /home/vsts/work/1/a/bins/publish/Modules/Pester/4.10.1/Pester.psm1: line 1111Error occurred in test script '/home/vsts/work/1/s/test/powershell/Language/Classes/scripting.Classes.inheritance.tests.ps1'
Object reference not set to an instance of an object.
at <ScriptBlock>, /home/vsts/work/1/a/bins/publish/Modules/Pester/4.10.1/Pester.psm1: line 1111Error occurred in test script '/home/vsts/work/1/s/test/powershell/Language/Classes/scripting.Classes.inheritance.tests.ps1'
Object reference not set to an instance of an object.
at <ScriptBlock>, /home/vsts/work/1/a/bins/publish/Modules/Pester/4.10.1/Pester.psm1: line 1111Error occurred in test script '/home/vsts/work/1/s/test/powershell/Language/Classes/scripting.Classes.inheritance.tests.ps1'
Object reference not set to an instance of an object.
at <ScriptBlock>, /home/vsts/work/1/a/bins/publish/Modules/Pester/4.10.1/Pester.psm1: line 1111There was a problem hiding this comment.
@IISResetMe, your last commit had 4 failures in PowerShell-CI-macos
Error occurred in test script '/Users/runner/runners/2.169.1/work/1/s/test/powershell/Language/Classes/scripting.Classes.inheritance.tests.ps1'
Object reference not set to an instance of an object.
at <ScriptBlock>, /Users/runner/runners/2.169.1/work/1/a/bins/publish/Modules/Pester/4.10.1/Pester.psm1: line 1111Error occurred in test script '/Users/runner/runners/2.169.1/work/1/s/test/powershell/Language/Classes/scripting.Classes.inheritance.tests.ps1'
Object reference not set to an instance of an object.
at <ScriptBlock>, /Users/runner/runners/2.169.1/work/1/a/bins/publish/Modules/Pester/4.10.1/Pester.psm1: line 1111Error occurred in test script '/Users/runner/runners/2.169.1/work/1/s/test/powershell/Language/Classes/scripting.Classes.inheritance.tests.ps1'
Object reference not set to an instance of an object.
at <ScriptBlock>, /Users/runner/runners/2.169.1/work/1/a/bins/publish/Modules/Pester/4.10.1/Pester.psm1: line 1111Error occurred in test script '/Users/runner/runners/2.169.1/work/1/s/test/powershell/Language/Classes/scripting.Classes.inheritance.tests.ps1'
Object reference not set to an instance of an object.
at <ScriptBlock>, /Users/runner/runners/2.169.1/work/1/a/bins/publish/Modules/Pester/4.10.1/Pester.psm1: line 1111There was a problem hiding this comment.
@IISResetMe, your last commit had 4 failures in PowerShell-CI-windows
Error occurred in test script 'D:\a\1\s\test\powershell\Language\Classes\scripting.Classes.inheritance.tests.ps1'
Object reference not set to an instance of an object.
at <ScriptBlock>, D:\a\1\s\src\powershell-win-core\bin\Release\net5.0\win7-x64\publish\Modules\Pester\4.10.1\Pester.psm1: line 1111Error occurred in test script 'D:\a\1\s\test\powershell\Language\Classes\scripting.Classes.inheritance.tests.ps1'
Object reference not set to an instance of an object.
at <ScriptBlock>, D:\a\1\s\src\powershell-win-core\bin\Release\net5.0\win7-x64\publish\Modules\Pester\4.10.1\Pester.psm1: line 1111Error occurred in test script 'D:\a\1\s\test\powershell\Language\Classes\scripting.Classes.inheritance.tests.ps1'
Object reference not set to an instance of an object.
at <ScriptBlock>, D:\a\1\s\src\powershell-win-core\bin\Release\net5.0\win7-x64\publish\Modules\Pester\4.10.1\Pester.psm1: line 1111Error occurred in test script 'D:\a\1\s\test\powershell\Language\Classes\scripting.Classes.inheritance.tests.ps1'
Object reference not set to an instance of an object.
at <ScriptBlock>, D:\a\1\s\src\powershell-win-core\bin\Release\net5.0\win7-x64\publish\Modules\Pester\4.10.1\Pester.psm1: line 1111|
Although some of there errors are surely mine, HEAD of Build from clean clone of |
|
You should be able to build in release mode in the meantime to bypass the debug assert and test things, but we do need #12840 fixed so we don't need to do that. 🙂 |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
By supplying the interface last up front when defining a new class, we rob
ourselves the opportunity to resolve the class in question as a generic type
parameter. This makes the following implementation - a completely valid type
definition - impossible in PowerShell:
class SortableThing : IComparable[SortableThing]
{
[int]Value
[int]
CompareTo([SortableThing]$obj)
{
return $this.Value.CompareTo($obj.Value)
}
}
This commit introduces an InterfaceExpression helper to bind the current
typebuilder to any matching type parameter in it's own interface list _after_
initial definition.
Changes introduced in 45727cb26 means that we might pass a partially unclosed type to ShouldImplementProperty() - this is more of a best-case workaround than a solution, ultimately we should refactor resolution of generic type parameter expressions completely,
c8137a0 to
6f4fc21
Compare
|
This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 15 days. It will be closed if no further activity occurs within 10 days of this comment. |

PR Summary
Delay type parameter-binding of unclosed (self-referential) type references in generic interface declarations
PR Context
We currently support implementing typed generic interfaces, but only if the type parameters can be resolved in the defining scope prior to defining the new type.
This makes the following implementation impossible in PowerShell:
To this end, the following changes have been made to the DefineTypeHelper in PSType:
GetBaseTypesnow outputs a list of late-bindingInterfaceExpression's rather than a list ofTypeinstances describing concrete interfacesTypeNotFoundAt some point we will need to re-think how we resolve generic type arguments, perhaps refactor
GenericTypeNamecompletely to natively support late binding against unclosed types, but I'll leave that an exercise for the future for now.PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.