@@ -31,6 +31,7 @@ internal sealed class GeneratorRewriter : DynamicExpressionVisitor {
3131 private readonly Expression _body ;
3232 private readonly string _name ;
3333 private readonly StrongBox < Type > _tupleType = new StrongBox < Type > ( null ) ;
34+ private readonly StrongBox < int > _tupleSize = new StrongBox < int > ( ) ;
3435 private readonly StrongBox < ParameterExpression > _tupleExpr = new StrongBox < ParameterExpression > ( null ) ;
3536
3637 // The one return label, or more than one if we're in a finally
@@ -101,6 +102,7 @@ internal Expression Reduce(bool shouldInterpret, bool emitDebugSymbols, int comp
101102
102103 Expression newTuple = MutableTuple . Create ( tupleExprs ) ;
103104 Type tupleType = _tupleType . Value = newTuple . Type ;
105+ _tupleSize . Value = tupleExprs . Length ;
104106 ParameterExpression tupleExpr = _tupleExpr . Value = Expression . Parameter ( tupleType , "tuple" ) ;
105107 ParameterExpression tupleArg = Expression . Parameter ( typeof ( MutableTuple ) , "tupleArg" ) ;
106108 _temps . Add ( _gotoRouter ) ;
@@ -152,7 +154,7 @@ internal Expression Reduce(bool shouldInterpret, bool emitDebugSymbols, int comp
152154 )
153155 ) ,
154156 new DelayedTupleAssign (
155- new DelayedTupleExpression ( liftedGen . Index , new StrongBox < ParameterExpression > ( tupleTmp ) , _tupleType , typeof ( PythonGenerator ) ) ,
157+ new DelayedTupleExpression ( liftedGen . Index , new StrongBox < ParameterExpression > ( tupleTmp ) , _tupleType , _tupleSize , typeof ( PythonGenerator ) ) ,
156158 ret
157159 ) ,
158160 ret
@@ -653,7 +655,7 @@ protected override Expression VisitBlock(BlockExpression node) {
653655 private DelayedTupleExpression LiftVariable ( ParameterExpression param ) {
654656 DelayedTupleExpression res ;
655657 if ( ! _vars . TryGetValue ( param , out res ) ) {
656- _vars [ param ] = res = new DelayedTupleExpression ( _vars . Count , _tupleExpr , _tupleType , param . Type ) ;
658+ _vars [ param ] = res = new DelayedTupleExpression ( _vars . Count , _tupleExpr , _tupleType , _tupleSize , param . Type ) ;
657659 _orderedVars . Add ( new KeyValuePair < ParameterExpression , DelayedTupleExpression > ( param , res ) ) ;
658660 }
659661
@@ -981,19 +983,21 @@ internal YieldMarker(int state) {
981983 internal sealed class DelayedTupleExpression : Expression {
982984 public readonly int Index ;
983985 private readonly StrongBox < Type > _tupleType ;
986+ private readonly StrongBox < int > _tupleSize ;
984987 private readonly StrongBox < ParameterExpression > _tupleExpr ;
985988 private readonly Type _type ;
986989
987- public DelayedTupleExpression ( int index , StrongBox < ParameterExpression > tupleExpr , StrongBox < Type > tupleType , Type type ) {
990+ public DelayedTupleExpression ( int index , StrongBox < ParameterExpression > tupleExpr , StrongBox < Type > tupleType , StrongBox < int > tupleSize , Type type ) {
988991 Index = index ;
989992 _tupleType = tupleType ;
993+ _tupleSize = tupleSize ;
990994 _tupleExpr = tupleExpr ;
991995 _type = type ;
992996 }
993997
994998 public override Expression Reduce ( ) {
995999 Expression res = _tupleExpr . Value ;
996- foreach ( PropertyInfo pi in MutableTuple . GetAccessPath ( _tupleType . Value , Index ) ) {
1000+ foreach ( PropertyInfo pi in MutableTuple . GetAccessPath ( _tupleType . Value , _tupleSize . Value , Index ) ) {
9971001 res = Expression . Property ( res , pi ) ;
9981002 }
9991003 return res ;
0 commit comments