Skip to content

Commit 9163a83

Browse files
bluewingHuangbluewingHuang
authored andcommitted
fix issue 499
1 parent 3d059a4 commit 9163a83

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/FastExpressionCompiler/FastExpressionCompiler.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2588,8 +2588,14 @@ private static bool TryEmitIndexGet(IndexExpression indexExpr,
25882588
var indexArgs = indexExpr.Arguments;
25892589
#endif
25902590
var indexArgCount = indexArgs.GetCount();
2591+
// Strip InstanceAccess when emitting arguments: they are parameters to the indexer
2592+
// getter method, not instances. Without this, a nested IndexExpression like
2593+
// `list[i][j]` leaks the outer InstanceAccess into the inner indexer's argument
2594+
// emission, causing value-type args (e.g. int) to be loaded by address (ldloca)
2595+
// instead of by value (ldloc), producing invalid IL. See #499.
2596+
var argParent = p & ~ParentFlags.InstanceAccess;
25912597
for (var i = 0; i < indexArgCount; i++)
2592-
if (!TryEmit(indexArgs.GetArgument(i), paramExprs, il, ref closure, setup, p, -1))
2598+
if (!TryEmit(indexArgs.GetArgument(i), paramExprs, il, ref closure, setup, argParent, -1))
25932599
return false;
25942600

25952601
var indexerProp = indexExpr.Indexer;

0 commit comments

Comments
 (0)