@@ -141,10 +141,16 @@ private List<String> subclassCreateClasses(String output, String baseName) {
141141 }
142142
143143 private String compileLuaWithRunArgs (String testName , boolean withStdLib , String ... lines ) {
144+ return compileLuaWithCUs (testName , withStdLib , Collections .emptyList (), lines );
145+ }
146+
147+ private String compileLuaWithCUs (String testName , boolean withStdLib , List <CU > extraCUs , String ... lines ) {
144148 RunArgs runArgs = new RunArgs ().with ("-lua" , "-inline" , "-localOptimizations" , "-stacktraces" );
145149 WurstGui gui = new WurstGuiCliImpl ();
146150 WurstCompilerJassImpl compiler = new WurstCompilerJassImpl (null , gui , null , runArgs );
147- List <CU > inputs = Collections .singletonList (new CU (testName + ".wurst" , String .join ("\n " , lines )));
151+ List <CU > inputs = new ArrayList <>();
152+ inputs .addAll (extraCUs );
153+ inputs .add (new CU (testName + ".wurst" , String .join ("\n " , lines )));
148154
149155 WurstModel model = parseFiles (Collections .emptyList (), inputs , withStdLib , compiler );
150156 assertNotNull ("parse returned null model, errors = " + gui .getErrorList (), model );
@@ -2316,22 +2322,26 @@ public void wurstInternalNativesDoNotGetNilSafetyWrapper() throws IOException {
23162322 }
23172323
23182324 @ Test
2319- public void isLuaMagicConstantIsTrueInLuaMode () throws IOException {
2320- // isLua must be inlined to true in Lua mode by GlobalsInliner,
2321- // so backend-specific code paths can be selected at compile time.
2322- test ().testLua (true ).withStdLib ().lines (
2325+ public void isLuaMagicConstantIsTrueInLuaMode () {
2326+ // isLua must be replaced with true by LuaNativeLowering so the optimizer can
2327+ // prune Jass-only branches at compile time. This test does NOT use withStdLib()
2328+ // to avoid dependence on the stdlib version pin in StdLib.java.
2329+ CU magicFunctions = new CU ("MagicFunctions.wurst" ,
2330+ "package MagicFunctions\n public constant isLua = false\n " );
2331+ String compiled = compileLuaWithCUs (
2332+ "LuaTranslationTests_isLuaMagicConstantIsTrueInLuaMode" ,
2333+ false ,
2334+ Collections .singletonList (magicFunctions ),
23232335 "package Test" ,
23242336 "import MagicFunctions" ,
2337+ "native print(string s)" ,
23252338 "init" ,
23262339 " if isLua" ,
23272340 " print(\" lua-path\" )" ,
23282341 " else" ,
23292342 " print(\" jass-path\" )"
23302343 );
2331- String compiled = Files .toString (
2332- new File ("test-output/lua/LuaTranslationTests_isLuaMagicConstantIsTrueInLuaMode.lua" ),
2333- Charsets .UTF_8 );
2334- // After inlining, the raw isLua variable must not appear in Lua output
2344+ // After LuaNativeLowering, all reads of MagicFunctions_isLua must be inlined to true
23352345 assertFalse ("MagicFunctions_isLua must be inlined away in Lua mode" , compiled .contains ("MagicFunctions_isLua" ));
23362346 // The lua-path branch must be preserved
23372347 assertTrue ("lua-path branch must be present" , compiled .contains ("lua-path" ));
0 commit comments