|
9 | 9 | import de.peeeq.wurstscript.ast.WurstModel; |
10 | 10 | import de.peeeq.wurstscript.intermediatelang.optimizer.FunctionSplitter; |
11 | 11 | import de.peeeq.wurstscript.intermediatelang.optimizer.LocalMerger; |
| 12 | +import de.peeeq.wurstscript.intermediatelang.optimizer.SideEffectAnalyzer; |
12 | 13 | import de.peeeq.wurstscript.jassIm.*; |
13 | 14 | import de.peeeq.wurstscript.translation.imtranslation.ImTranslator; |
| 15 | +import de.peeeq.wurstscript.translation.imtranslation.FunctionFlagEnum; |
14 | 16 | import de.peeeq.wurstscript.types.TypesHelper; |
15 | 17 | import de.peeeq.wurstscript.utils.Utils; |
16 | 18 | import io.vavr.collection.HashSet; |
@@ -1156,6 +1158,39 @@ public void testFunctionSplitter() { |
1156 | 1158 |
|
1157 | 1159 | } |
1158 | 1160 |
|
| 1161 | + @Test |
| 1162 | + public void externCallIsObservableSideEffectEvenWithEmptyBody() { |
| 1163 | + WurstModel model = Ast.WurstModel(); |
| 1164 | + ImTranslator tr = new ImTranslator(model, false, new RunArgs()); |
| 1165 | + ImProg prog = tr.getImProg(); |
| 1166 | + Element trace = Ast.NoExpr(); |
| 1167 | + |
| 1168 | + ImFunction externFunc = JassIm.ImFunction( |
| 1169 | + trace, |
| 1170 | + "someExternCall", |
| 1171 | + JassIm.ImTypeVars(), |
| 1172 | + JassIm.ImVars(), |
| 1173 | + TypesHelper.imInt(), |
| 1174 | + JassIm.ImVars(), |
| 1175 | + JassIm.ImStmts(), |
| 1176 | + Collections.singletonList(FunctionFlagEnum.IS_EXTERN) |
| 1177 | + ); |
| 1178 | + prog.getFunctions().add(externFunc); |
| 1179 | + |
| 1180 | + ImFunctionCall externCall = JassIm.ImFunctionCall( |
| 1181 | + trace, |
| 1182 | + externFunc, |
| 1183 | + JassIm.ImTypeArguments(), |
| 1184 | + JassIm.ImExprs(), |
| 1185 | + false, |
| 1186 | + de.peeeq.wurstscript.translation.imtranslation.CallType.NORMAL |
| 1187 | + ); |
| 1188 | + |
| 1189 | + SideEffectAnalyzer analyzer = new SideEffectAnalyzer(prog); |
| 1190 | + assertTrue(analyzer.hasObservableSideEffects(externCall, f -> false), |
| 1191 | + "extern calls must be treated as observable side effects"); |
| 1192 | + } |
| 1193 | + |
1159 | 1194 | @Test |
1160 | 1195 | public void unaryMinus_minInt_notFolded() { |
1161 | 1196 | testAssertOkLines(true, |
|
0 commit comments