1313import de .peeeq .wurstscript .types .TypesHelper ;
1414import de .peeeq .wurstscript .types .WurstType ;
1515import de .peeeq .wurstscript .types .WurstTypeArray ;
16+ import de .peeeq .wurstscript .types .WurstTypeInt ;
1617import de .peeeq .wurstscript .types .WurstTypeVararg ;
1718import org .eclipse .jdt .annotation .Nullable ;
1819
@@ -293,8 +294,8 @@ private static ImStmt case_StmtForRange(ImTranslator t, ImFunction f, LocalVarDe
293294 List <ImStmt > result = Lists .newArrayList ();
294295 result .add (ImSet (loopVar , ImVarAccess (imLoopVar ), fromExpr ));
295296
296- ImExpr toExpr = addCacheVariableSmart (t , f , result , to , TypesHelper .imInt ());
297- ImExpr stepExpr = addCacheVariableSmart (t , f , result , step , TypesHelper .imInt ());
297+ ImExpr toExpr = addCacheVariableSmart (t , f , result , to , TypesHelper .imInt (), WurstTypeInt . instance () );
298+ ImExpr stepExpr = addCacheVariableSmart (t , f , result , step , TypesHelper .imInt (), WurstTypeInt . instance () );
298299
299300 ImStmts imBody = ImStmts ();
300301 // exitwhen imLoopVar > toExpr
@@ -310,6 +311,18 @@ private static ImStmt case_StmtForRange(ImTranslator t, ImFunction f, LocalVarDe
310311
311312 private static ImExpr addCacheVariableSmart (ImTranslator t , ImFunction f , List <ImStmt > result , Expr toCache , ImType type ) {
312313 ImExpr r = toCache .imTranslateExpr (t , f );
314+ return addCacheVariableSmart (t , f , result , toCache , type , r );
315+ }
316+
317+ private static ImExpr addCacheVariableSmart (ImTranslator t , ImFunction f , List <ImStmt > result ,
318+ Expr toCache , ImType type , WurstType expectedType ) {
319+ ImExpr r = toCache .imTranslateExpr (t , f );
320+ r = ExprTranslation .wrapTranslation (toCache , t , r , toCache .attrTypRaw (), expectedType );
321+ return addCacheVariableSmart (t , f , result , toCache , type , r );
322+ }
323+
324+ private static ImExpr addCacheVariableSmart (ImTranslator t , ImFunction f , List <ImStmt > result ,
325+ Expr toCache , ImType type , ImExpr r ) {
313326 if (r instanceof ImConst ) {
314327 return r ;
315328 }
0 commit comments