SeeminglyScience / PSLambda

A runtime compiler for PowerShell ScriptBlock objects.
MIT License
61 stars 3 forks source link

Add support for generic argument inference #2

Closed SeeminglyScience closed 6 years ago

SeeminglyScience commented 6 years ago

Method resolution should infer generic arguments from the expression tree. Currently if generic arguments aren't specified explicitly with the generic keyword resolution will fail.

The work around is to use generic:

$delegate = [psdelegate]{ generic ([array]::Empty(), [int]) }
$delegate.Invoke().GetType()
# IsPublic IsSerial Name       BaseType
# -------- -------- ----       --------
# True     True     Int32[]    System.Array

$delegate = [psdelegate]{ generic ([tuple]::Create(10, 'string'), [int], [string]) }
$delegate.Invoke()
# Item1 Item2  Length
# ----- -----  ------
#    10 string      2