Skip to content

Commit ad4544e

Browse files
Fix indexing for IEnumerable<> typed expressions
If an expression was typed as IEnumerable<> specifically (like Linq method results) the indexer was not being inferred correctly.
1 parent 9e44b65 commit ad4544e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/PSLambda/CompileVisitor.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,15 @@ public object VisitIndexExpression(IndexExpressionAst indexExpressionAst)
544544
new[] { indexExpressionAst.Index.Compile(this) });
545545
}
546546

547-
if (TryFindGenericInterface(source.Type, typeof(IEnumerable<>), out Type genericEnumerable))
547+
if (TryFindGenericInterface(source.Type, typeof(IEnumerable<>), out Type genericEnumerable) ||
548+
(source.Type.IsGenericType &&
549+
source.Type.GetGenericTypeDefinition() == typeof(IEnumerable<>)))
548550
{
551+
if (genericEnumerable == null)
552+
{
553+
genericEnumerable = source.Type;
554+
}
555+
549556
Expression index;
550557
try
551558
{

0 commit comments

Comments
 (0)