@@ -259,20 +259,16 @@ private void ProcessStatementFor(DMASTProcStatementFor statementFor) {
259259 ProcessStatementVarDeclaration ( new DMASTProcStatementVarDeclaration ( statementFor . Location , decl . DeclPath , null , DMValueType . Anything ) ) ;
260260 }
261261
262- if ( statementFor is { Expression2 : DMASTExpressionIn dmastIn , Expression3 : null } ) {
263- var expr2 = statementFor . Expression2 != null ? _exprBuilder . CreateIgnoreUnknownReference ( statementFor . Expression2 ) : null ;
262+ if ( statementFor is { Expression2 : DMASTExpressionIn dmastIn , Expression3 : null } ) { // for(var/i,j in expr) or for(i,j in expr)
263+ var valueVar = statementFor . Expression2 != null ? _exprBuilder . CreateIgnoreUnknownReference ( statementFor . Expression2 ) : null ;
264+ var list = _exprBuilder . Create ( dmastIn . RHS ) ;
264265
265266 // TODO: Wow this sucks
266- if ( expr2 is UnknownReference unknownRef ) {
267- if ( statementFor . Expression1 is not DMASTVarDeclExpression || dmastIn . LHS is not DMASTIdentifier ident )
267+ if ( valueVar is UnknownReference unknownRef ) { // j in var/i,j isn't already a var
268+ if ( dmastIn . LHS is not DMASTIdentifier ident )
268269 unknownRef . EmitCompilerError ( compiler ) ;
269- else {
270+ else
270271 ProcessStatementVarDeclaration ( new DMASTProcStatementVarDeclaration ( statementFor . Location , new DMASTPath ( statementFor . Location , new DreamPath ( ident . Identifier ) ) , null , DMValueType . Anything ) ) ;
271- var meep = dmastIn . LHS ;
272- expr2 = _exprBuilder . Create ( meep ) ;
273- }
274- } else {
275- expr2 = _exprBuilder . Create ( dmastIn . LHS ) ;
276272 }
277273
278274 DMASTExpression outputExpr ;
@@ -282,10 +278,10 @@ private void ProcessStatementFor(DMASTProcStatementFor statementFor) {
282278 outputExpr = statementFor . Expression1 ;
283279 }
284280
285- var outputVar = _exprBuilder . Create ( outputExpr ) ;
286- var list = _exprBuilder . Create ( dmastIn . RHS ) ;
281+ var keyVar = _exprBuilder . Create ( outputExpr ) ;
282+ valueVar = _exprBuilder . Create ( dmastIn . LHS ) ;
287283
288- switch ( outputVar ) {
284+ switch ( keyVar ) {
289285 case Local outputLocal : {
290286 outputLocal . LocalVar . ExplicitValueType = statementFor . DMTypes ;
291287 if ( outputLocal . LocalVar is DMProc . LocalConstVariable )
@@ -298,7 +294,7 @@ private void ProcessStatementFor(DMASTProcStatementFor statementFor) {
298294 }
299295 }
300296
301- switch ( expr2 ) {
297+ switch ( valueVar ) {
302298 case Local assocLocal : {
303299 assocLocal . LocalVar . ExplicitValueType = statementFor . DMTypes ;
304300 if ( assocLocal . LocalVar is DMProc . LocalConstVariable )
@@ -311,7 +307,7 @@ private void ProcessStatementFor(DMASTProcStatementFor statementFor) {
311307 }
312308 }
313309
314- ProcessStatementForList ( list , outputVar , expr2 , statementFor . DMTypes , statementFor . Body ) ;
310+ ProcessStatementForList ( list , keyVar , valueVar , statementFor . DMTypes , statementFor . Body ) ;
315311 } else if ( statementFor . Expression2 != null || statementFor . Expression3 != null ) {
316312 var initializer = statementFor . Expression1 != null ? _exprBuilder . Create ( statementFor . Expression1 ) : null ;
317313 var comparator = statementFor . Expression2 != null ? _exprBuilder . Create ( statementFor . Expression2 ) : null ;
@@ -459,9 +455,8 @@ private void ProcessLoopAssignment(LValue lValue, LValue? assocValue = null, DME
459455 } else {
460456 if ( assocValue != null && list != null ) {
461457 DMReference assocRef = assocValue . EmitReference ( ExprContext , string . Empty ) ;
462- DMReference listRef = list . EmitReference ( ExprContext , string . Empty ) ;
463458 DMReference outputRef = lValue . EmitReference ( ExprContext , string . Empty ) ;
464- proc . EnumerateAssoc ( assocRef , listRef , outputRef ) ;
459+ proc . EnumerateAssoc ( assocRef , outputRef ) ;
465460 } else {
466461 DMReference outputRef = lValue . EmitReference ( ExprContext , string . Empty ) ;
467462 proc . Enumerate ( outputRef ) ;
0 commit comments