Skip to content

The first array type in a generic method doesn't work #18686

@InSb

Description

@InSb

Prerequisites

Steps to reproduce

When I try to flatten a two-dimensional array by Enumerable.SelectMany method with generic type arguments, the first type argument int[] may not be treated correctly.

[Linq.Enumerable]::SelectMany[int[], int](
  [int[][]] @((,2), (,4), (,6), (,8)),
  [Func[[int[]], int[]]] { param ($x); $x }
) | ConvertTo-Json -Compress

Expected behavior

[2,4,6,8]

Actual behavior

Unable to find type [int,int].

Error details

Exception             :
    Type        : System.Management.Automation.RuntimeException
    ErrorRecord :
        Exception             :
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : Unable to find type [int,int].
            HResult : -2146233087
        TargetObject          : int,int
        CategoryInfo          : InvalidOperation: (int,int:TypeName) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : TypeNotFound
        InvocationInfo        :
            ScriptLineNumber : 2
            OffsetInLine     : 31
            HistoryId        : -1
            Line             : [Linq.Enumerable]::SelectMany[int[], int](

            PositionMessage  : At line:2 char:31
                               + [Linq.Enumerable]::SelectMany[int[], int](
                               +                               ~~~~~
            CommandOrigin    : Internal
        ScriptStackTrace      : at <ScriptBlock>, <No file>: line 2
    TargetSite  :
        Name          : ResolveTypeName
        DeclaringType : System.Management.Automation.TypeOps, System.Management.Automation, Version=7.3.0.500, Culture=
neutral, PublicKeyToken=31bf3856ad364e35
        MemberType    : Method
        Module        : System.Management.Automation.dll
    Message     : Unable to find type [int,int].
    Data        : System.Collections.ListDictionaryInternal
    Source      : System.Management.Automation
    HResult     : -2146233087
    StackTrace  :
   at System.Management.Automation.TypeOps.ResolveTypeName(ITypeName typeName, IScriptExtent errorPos)
   at System.Management.Automation.TypeOps.ResolveTypeName(ITypeName typeName, IScriptExtent errorPos)
   at System.Management.Automation.Adapter.ResolveGenericTypeParameters(Object[] genericTypeParameters)
   at System.Management.Automation.Adapter.FindBestMethodImpl(MethodInformation[] methods, PSMethodInvocationConstraint
s invocationConstraints, Boolean allowCastingToByRefLikeType, Object[] arguments, String& errorId, String& errorMsg, Bo
olean& expandParamsOnBest)
   at System.Management.Automation.Adapter.FindBestMethod(MethodInformation[] methods, PSMethodInvocationConstraints in
vocationConstraints, Boolean allowCastingToByRefLikeType, Object[] arguments, String& errorId, String& errorMsg, Boolea
n& expandParamsOnBest, Boolean& callNonVirtually)
   at System.Management.Automation.Language.PSInvokeMemberBinder.InvokeDotNetMethod(CallInfo callInfo, String name, PSM
ethodInvocationConstraints psMethodInvocationConstraints, MethodInvocationType methodInvocationType, DynamicMetaObject
target, DynamicMetaObject[] args, BindingRestrictions restrictions, MethodInformation[] mi, Type errorExceptionType)
   at System.Management.Automation.Language.PSInvokeMemberBinder.FallbackInvokeMember(DynamicMetaObject target, Dynamic
MetaObject[] args, DynamicMetaObject errorSuggestion)
   at System.Dynamic.DynamicMetaObjectBinder.Bind(Object[] args, ReadOnlyCollection`1 parameters, LabelTarget returnLab
el)
   at System.Runtime.CompilerServices.CallSiteBinder.BindCore[T](CallSite`1 site, Object[] args)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
   at System.Management.Automation.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
TargetObject          : int,int
CategoryInfo          : InvalidOperation: (int,int:TypeName) [], RuntimeException
FullyQualifiedErrorId : TypeNotFound
InvocationInfo        :
    ScriptLineNumber : 2
    OffsetInLine     : 31
    HistoryId        : -1
    Line             : [Linq.Enumerable]::SelectMany[int[], int](

    PositionMessage  : At line:2 char:31
                       + [Linq.Enumerable]::SelectMany[int[], int](
                       +                               ~~~~~
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 2

Environment data

Name                           Value
----                           -----
PSVersion                      7.3.0
PSEdition                      Core
GitCommitId                    7.3.0
OS                             Microsoft Windows 10.0.22621
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions